python - 从 Python 中的 webbrowser.get() 调用 Chrome 网络浏览器

标签 python google-chrome browser ubuntu-11.04

我应该如何调用 webbrowser.get() 函数才能打开 chrome 网络浏览器?我正在运行 Ubuntu 11.04 和 Python 2.7 版。 使用 webbrowser.get('chrome') 会产生错误。

最佳答案

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

编辑

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

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

即在 get() 的参数中包含“%s”是关键特性。

关于python - 从 Python 中的 webbrowser.get() 调用 Chrome 网络浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6042335/

相关文章:

python - 根据数据库验证 MySQL 的最快方法

python - beautifulsoup - TypeError : sequence item 0: expected string, 找到标签

html - 如何使用HTML5或WEBRTC在浏览器中发送UDP包?

html - 我不想调整弹出窗口的大小

python - 列表列表的独特元素

python - 我无法在 Django 1.5.4 和 Ubuntu 13.04 EC2 中安装 django-tracking

javascript - Chrome 扩展 : How to manipulate browser_action. default_popup DOM

css - 高度 : 100% for textarea causes vertical scroll bar in Chrome

css - 在高 DPI 显示器上,div 背景和边框之间有 0-1px 的间隙

javascript - 网络浏览器 Windows Phone 7 中的上下文菜单