9

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.

Dananjaya
  • 2,135
  • 8
  • 22
  • 27

2 Answers2

10

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.

zindel
  • 1,837
  • 11
  • 13
  • yeah it could work, but the application that I'm writing requires I call the browser that way. I'm writing a small utility script that invokes a browser user chooses with some urls already loaded in the tabs. – Dananjaya May 18 '11 at 09:29
  • Thanks! it worked. Although I need to refine my program a bit. I'm using a for-loop to supply the urls for all new tabs, but it appears, chrome waits until one tab is closed to open the other tab. – Dananjaya May 18 '11 at 09:48
  • 2
    Perhaps try the open_new_tab() method? – zindel May 18 '11 at 10:17
  • Cross platform version would be nice. – Drew Mar 24 '12 at 22:21
3

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

Jackie Lee
  • 239
  • 3
  • 3