gpt4 book ai didi

python - Webdriver 异常 :Process unexpectedly closed with status: 1

转载 作者:太空狗 更新时间:2023-10-29 18:15:10 32 4
gpt4 key购买 nike

我尝试在 Linux 机器上运行一个 selenium 程序。但是我遇到了异常:

    Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 154, in __init__
keep_alive=True)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 151, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 240, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 308, in execute
self.error_handler.check_response(response)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status: 1

如何修复异常?感谢您的帮助。

最佳答案

当您尝试在没有显示器的盒子(如 Ubuntu 服务器)上以非 headless 模式运行浏览器时,可能会出现此错误。

您可以通过查看通常留在您的工作目录中的 geckodriver.log 文件来检查这是否是您的 Process unexpectedly closed with status: 1 错误的原因运行脚本后,它应该有一行:

Error: GDK_BACKEND does not match available displays

如果您在 geckodriver.log 中看到该行,那么您需要切换脚本以在 headless 模式下运行 Firefox:

from selenium import webdriver
from selenium.webdriver import FirefoxOptions

opts = FirefoxOptions()
opts.add_argument("--headless")
browser = webdriver.Firefox(options=opts)

browser.get('http://example.com')

关于python - Webdriver 异常 :Process unexpectedly closed with status: 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46809135/

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