gpt4 book ai didi

python - Selenium WebDriverException - 无法访问 chrome

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

我在 linux 服务器上有一个 chrome selenium 驱动程序,它由 cron 每小时执行一次。我遇到的错误只发生在后续运行中,也就是说,在第一次运行期间它工作正常,但在第二次或任何其他后续运行期间它失败了。

raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
(Session info: chrome=54.0.2840.71)
(Driver info: chromedriver=2.26.436382 (70eb799287ce4c2208441fc057053a5b07ceabac),platform=Linux 4.4.0-38-generic x86_64)

我是这样运行的:

def create_ch_driver():
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--user-agent={}".format(config.USER_AGENT))
return webdriver.Chrome("/usr/local/bin/chromedriver", chrome_options=chrome_options)

最佳答案

也许驱动程序仍在后台运行并阻止创建新的 webdriver 实例。

在第一次执行代码后检查进程是否正在运行。

如果是这样,尝试使用 quit() 终止进程:

webdriver.quit()

关于python - Selenium WebDriverException - 无法访问 chrome,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41195382/

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