开发者

Python3.1 - Open Opera

I have no idea why this won't work....I'm trying to open opera but it says cannot find runnable browser.

op = webbrowser.get('C:\\Program Files\\Ope开发者_StackOverflow中文版ra\\opera.exe')

op.open_new_tab('http://www.stackoverflow.com')
op.open_new_tab('http://www.stackoverflow.com')


The name parameter should just be 'opera':

op = webbrowser.get('opera')

Make sure you have installed Opera on your computer, and that the executable opera.exe is in the path.

>>> import webbrowser
>>> webbrowser.get('opera')
<webbrowser.BackgroundBrowser object at 0x02095490>

See the table of allowed values for the name parameter in the documentation.

If you want to specify the exact path to the executable (which by the way is a bad idea if you want your application to be portable) then you can specify the command line as follows:

op = webbrowser.get(r'C:\\Program Files\\Opera\\opera.exe %s')


As far as I know, you cannot provide a specific filepath for the browser you want to associate with the webbrowser object. You need to just provide one of a few built-in names. The one you want here is "opera" - see http://docs.python.org/py3k/library/webbrowser.html for details.


You should try to set the browser path to BROWSER environment variable.

Here's how to do it in Windows (which you are apparently using): http://vlaurie.com/computers2/Articles/environment.htm

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜