gpt4 book ai didi

linux - Linux 上的 Xvfb Selenium headless Chrome 和 Python

转载 作者:太空宇宙 更新时间:2023-11-04 12:13:09 26 4
gpt4 key购买 nike

我正在尝试在 Python 中使用 selenium headless 运行 chrome。我试过 xvfb-run -a python3 message.py我得到这个错误:

Traceback (most recent call last):
File "message.py", line 388, in <module>
initialize()
File "message.py", line 54, in initialize
driver = webdriver.Chrome(chrome_options = chrome_options)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
(Driver info: chromedriver=2.33.506178 (69ae10f91723897591ef1a3b465aa5d35011eb5e),platform=Linux 3.13.0-96-generic x86)

和初始化():

   chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--verbose")
chrome_options.add_argument("--log-path=chrome.log")
chrome_options.add_argument("window-size=1200x600")
chrome_options.add_argument("user-data-dir=\\")
driver = webdriver.Chrome(chrome_options = chrome_options)
driver.get('http://google.com')

我在 Linux32 上使用 Python 3.5 和 chromedriver 2.33.506178(Ubuntu 作为没有桌面的服务器)我在我的另一台电脑上用 linux mint 测试了相同的代码,一切正常。

希望你能帮助我:)

最佳答案

在检查了我的写/读/执行的实际权限后,我发现了我的错误。 chromedriver 在尝试以 root 权限执行时无法加载。在我更改 chromedrivers 权限后,现在一切正常。

关于linux - Linux 上的 Xvfb Selenium headless Chrome 和 Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48230322/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com