Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 825
Dananjaya Avatar asked May 18 '11 09:05

Dananjaya


2 Answers

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.

like image 79
zindel Avatar answered Sep 25 '22 01:09

zindel


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

like image 44
Jackie Lee Avatar answered Sep 22 '22 01:09

Jackie Lee