0

I had try with python with webbrowser.open, but it only work on IE. How to let it open chrome or firefox. I don't want it to open on IE, i wants to be open on Chrome or Firefox. Due to i try many method, but none of them works.

import time import webbrowser webbrowser.open('www.google.com') 
1

1 Answer 1

1

you need specify your webbrowser's name, detal see webbrowser.get

import webbrowser webbrowser.open('www.google.com') a = webbrowser.get('firefox') a.open('www.google.com') # True 

UPDATE
If you have chrome or firefox installed in your computer, do as following:

chrome_path =r'C:\Users\Administrator\AppData\Local\Google\Chrome\Application\chrome.exe' # change to your chrome.exe path # webbrowser is just call subprocess.Popen, so make sure this work in your cmd firstly # C:\Users\Administrator>C:\Users\Administrator\AppData\Local\Google\Chrome\Application\chrome.exe www.google.com # there two way solve your problem # you have change \ to / in windows # this seems a bug in browser = shlex.split(browser) in windows # ['C:UsersAdministratorAppDataLocalGoogleChromeApplicationchrome.exe', '%s'] a = webbrowser.get(r'C:/Users/Administrator/AppData/Local/Google/Chrome/Application/chrome.exe %s') a.open('www.google.com') #True # or by register webbrowser.register('chrome', None,webbrowser.BackgroundBrowser(r'C:\Users\Administrator\AppData\Local\Google\Chrome\Application\chrome.exe')) a = webbrowser.get('chrome') a.open('www.google.com') #True 

else you can try selenium, it provide much more functions and only need chromedriver.

Sign up to request clarification or add additional context in comments.

1 Comment

i try with it \, and it will pop up: >>> a = webbrowser.get('firefox') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\user\AppData\Local\Programs\Python\Python35-32\lib\webbrowser.py", line 51, in get raise Error("could not locate runnable browser") webbrowser.Error: could not locate runnable browser >>>

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.