はあなたのwebbrowser's name
、webbrowser.get
参照DETAL指定する必要があります
import webbrowser
webbrowser.open('www.google.com')
a = webbrowser.get('firefox')
a.open('www.google.com') # True
UPDATE
あなたがchrome
かfirefox
がコンピュータにインストールされている場合は、次のようにしてください:
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
を
他にも、seleniumを試すことができます。これははるかに多くの機能を提供し、必要なのはchromedriverです。
私は\それをしようと、それがポップアップ表示されます: >>> A = webbrowser.get( 'Firefoxの') トレースバック(最新の呼び出しの最後): で ファイル ""、ライン1、ファイル "C:¥Users¥user¥AppData¥Local¥Programs¥Python¥Python35-32¥lib¥webbrowser.py"、行51、取得 raiseエラー( "runnableブラウザが見つかりませんでした") webbrowser.Error:実行可能なブラウザを見つけることができませんでした >>> –
jacklee26
@ jacklee26私の更新を参照してください – Cheney
ありがとうございます。それはすぐにクロムで動作します。 – jacklee26