问题描述
我正在一个项目中,我需要使用python在Ubuntu中的Firefox中打开url
。为此,我有以下代码:
import webbrowser
webbrowser.open('https://www.google.com')
这在Windows中工作正常,并且在OS中可用的默认浏览器中打开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,然后在网络浏览器代码中使用chrome。但还是一样。我什至尝试修改google-chrome
文件,但它始终抛出相同的错误。由于某些原因,我必须将代码作为sudo运行,因此需要此代码。谁能帮忙。谢谢
解决方法
我建议使用 Selenium ,但您需要先安装Webdriver
from selenium import webdriver
browser = webdriver.Chrome()
browser.get('https://www.google.com')