Calling Chrome web browser from the webbrowser.get() in Python

杀马特。学长 韩版系。学妹 提交于 2019-12-22 04:39:06

问题


How I should call webbrowser.get() function so I open the chrome web browser? I'm running Ubuntu 11.04 and Python version 2.7. Using webbrowser.get('chrome') yields an error.


回答1:


The quick workaround is to make Chrome the default browser in your system and then use simply webbrowser.get(). I've just checked that on ubuntu 10.10 and it worked just fine.

EDIT

Just reviewed the code of /usr/lib/python2.6/webbrowser.py. You should do like this:

In [5]: webbrowser.get('/usr/bin/google-chrome %s').open('http://google.com')
Created new window in existing browser session.
Out[5]: True

In [6]: webbrowser.get('firefox %s').open('http://google.com')
Out[6]: True

I.e. having '%s' in get()'s parameter is the key feature.




回答2:


for mac, do this
webbrowser.get("open -a /Applications/Google\ Chrome.app %s").open("http://google.com")



来源:https://stackoverflow.com/questions/6042335/calling-chrome-web-browser-from-the-webbrowser-get-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!