从Python的webbrowser.get()调用Chrome浏览器 [英] Calling Chrome web browser from the webbrowser.get() in Python

查看:3783
本文介绍了从Python的webbrowser.get()调用Chrome浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该如何调用webbrowser.get()函数,以便打开Chrome浏览器?我正在运行Ubuntu 11.04和Python版本2.7。
使用webbrowser.get('chrome')会产生错误。 解决方案

快速解决方法是使Chrome成为系统中的默认浏览器,然后使用webbrowser.get()。我刚刚在ubuntu 10.10上检查过,它工作得很好。



编辑



刚刚查看了/usr/lib/python2.6/webbrowser.py的代码。您应该这样做:

 在[5]中:webbrowser.get('/ usr / bin / google-chrome%s ').open('http://google.com')
在现有浏览器会话中创建新窗口。
Out [5]:True

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

Ie在get()的参数中有'%s'是关键功能。


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.

解决方案

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.

这篇关于从Python的webbrowser.get()调用Chrome浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆