WebDriver异常:消息:长时间后无法访问chrome



这是代码:

driver = webdriver.Chrome()
while True:
#do thing that require hours
#then i use selenium once
driver.get(link)

我需要先打开硒,然后制作需要数小时的东西,因为当我打开硒时,我需要做好准备并加快速度。如果driver = webdriver.Chrome()放在 while 以下,它会减慢一切 我不知道它是否相关,但我使用nohup命令运行此代码。

追踪:

Traceback (most recent call last):
File "Scraper.py", line 84, in <module>
main()
File "Scraper.py", line 74, in main
waitForSomething()
File "Scraper.py", line 54, in waitForSomething
fillForm(str(link)[2:-2])
File "Scraper.py", line 30, in fillForm
driver.get(link)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_resp$
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
(Session info: chrome=192.168.0.0)
(Driver info: chromedriver=2.36.540471 (9c759b81a907e70363c6312294d30b6ccccc2752),platform=Linux 4.9.0-9-amd64 x$

最初,我问自己与@GregBurghardt在评论中提出的问题相同,直到我分析了详细的错误堆栈跟踪。

是的,在那些标记为#do thing that require hours的步骤中发生了一些惊人的事情。因此,将Chrome浏览器版本显示为chrome=76.0chrome=75.0chrome=74.0它显示:

(Session info: chrome=192.168.0.0)

这非常令人惊讶。

除非您向我们更新Chrome版本更改为此值的原因和方式,否则几乎不可能分析该问题。


话虽如此,您的主要问题可能是您使用的二进制文件版本之间的不兼容

  • 您正在使用的 chromedriver=2.36
  • chromedriver=2.36的发行说明明确提到了以下内容:

支持铬 v63-65

  • 大概您正在使用最新的chrome= 76.0
  • ChromeDriver v76.0的发行说明明确提到了以下内容:

支持Chrome 版本 76

  • 我们不知道您的硒客户端版本。

因此,ChromeDriver v2.36和Chrome浏览器v76.0之间存在明显的不匹配


溶液

确保:

  • 已升级到当前级别 版本 3.141.59。
  • ChromeDriver已更新到当前的 ChromeDriver v76.0 级别。
  • Chrome
  • 已更新到当前的Chrome 版本 76.0级别。(根据ChromeDriver v76.0发行说明(
  • 通过IDE清理项目工作中心,并仅使用所需的依赖项重新生成项目。
  • 如果基本 Web 客户端版本太旧,请将其卸载并安装最新的 GA 和已发布版本的Web 客户端
  • 重新启动系统
  • 非 root用户身份执行@Test
  • 始终在方法中调用driver.quit()tearDown(){}以正常关闭和销毁WebDriverWeb 客户端实例。

引用:

  • Python Selenium WebDriverException:打开ChromeDriver时无法访问chrome
  • selenium.common.exceptions.WebDriverException: 消息:将 find_element_by_id Selenium 与 ChromeDrive 一起使用时出现 chrome 无法访问错误
  • org.openqa.selenium.WebDriver异常:无法访问chrome - 尝试启动新会话时

就我而言,我正在使用服务器来启动该应用程序。这是因为我有很多谷歌浏览器活动进程正在运行,所以铬不堪重负。

您可以使用ps -aux命令检查这一点并查看谷歌流程。

就我而言,因为我没有使用try driver.get(url) , except: driver.close()所有那些失败的attemtps都在我的服务器中保持打开状态。

我用killall usernamehere把他们都杀了

然后它又起作用了。

希望它也适合你

最新更新