According to the documentation http://docs.python.org/3.3/library/webbrowser.html it's supposed to open in the default browser, but for some reason on my machine it opens IE. I did a google search and I came across an answer that said I need to register browsers, but I'm not sure how to use webbrowser.register() and the documentation doesn't seem to be very clear. How do I register Chrome so that urls I pass to webbrowser.open() open in Chrome instead of IE?
To open a page in a specific browser, use the webbrowser. get() function to specify a particular browser.
just open the python interpreter and type webbrowser. open('http://www.google.com') and see if it does what you want. yes. The result is same.
You can call get() with the path to Chrome. Below is an example - replace chrome_path with the correct path for your platform.
import webbrowser
url = 'http://docs.python.org/'
# MacOS
chrome_path = 'open -a /Applications/Google\ Chrome.app %s'
# Windows
# chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
# Linux
# chrome_path = '/usr/bin/google-chrome %s'
webbrowser.get(chrome_path).open(url)
In the case of Windows, the path uses a UNIX-style path, so make the backslash into forward slashes.
webbrowser.get("C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s").open("http://google.com")
See: Python: generic webbrowser.get().open() for chrome.exe does not work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With