python - 如何在 Ubuntu 中使用 Python 在 firfox 中打开网页
问题描述
我正在做一个项目,我需要url
使用 python 在 Ubuntu 中打开一个 Firefox。为此,我有以下代码:
import webbrowser
webbrowser.open('https://www.google.com')
这在 Windows 中运行良好,并且google.com
在操作系统中可用的默认浏览器中打开。但在 Ubuntu 的情况下,我遇到了 Firefox 的以下错误:
[6858:6858:0929/111955.830869:ERROR:zygote_host_impl_linux.cc(90)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
[6868:6868:0929/111955.853440:ERROR:zygote_host_impl_linux.cc(90)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
Running Firefox as root in a regular user's session is not supported.
我想安装 chrome,然后在 webbrowser 代码中使用 chrome。但还是一样。我什至尝试修改google-chrome
文件,但它一直抛出同样的错误。出于某种原因,我必须将代码作为 sudo 运行,因此需要它。任何人都可以请帮忙。谢谢
解决方案
我会推荐Selenium,但你需要先安装 webdriver
from selenium import webdriver
browser = webdriver.Chrome()
browser.get('https://www.google.com')
推荐阅读
- version-control - 完全本地和有限制的版本控制?
- elasticsearch - 如何使用 NEST 在 Easticsearch 中按索引获取所有文档?
- javascript - 选择一个选择框后加载sql数据?
- f# - 我可以在运行时解析一些引用当前程序集中类型的 F# 代码吗?
- aws-lambda - 通过 lambda 重新排队接收到的 SQS 消息
- php - 从数组中删除分号分隔的值并添加为新值
- python - ValueError:无法将字符串转换为浮点数,CSV 中的值无法转换为浮点数
- opc-ua - 如何从 OPCUA 中的数据 changed_notification 中获取节点的名称(字符串)?
- java - Spring JPA:使用 saveAndFlush 时 @OrderBy 不起作用
- python - 使用 matplotlib.widgets 中的 Slider 后如何获取条形图值?