Python Selenium在长时间运行后出现的问题

Python Selenium在长时间运行后出现的问题,python,firefox,selenium,web-scraping,Python,Firefox,Selenium,Web Scraping,我一直在使用Selenium作为刮板/爬虫,因为在评估JS之后,我需要一个页面的内容。我有五台EC2机器,每台都运行selenium,还有我编写的几个scraper实例 然而,我注意到一些非常奇怪的行为。几个小时后,selenium几乎同时在所有机器上停止运行。考虑到我在所有服务器上同时启动selenium和Scraper,这让我相信selenium在长时间运行后会出现一些问题 以下是selenium的日志: 14:34:58.628 INFO - RemoteWebDriver instanc

我一直在使用Selenium作为刮板/爬虫,因为在评估JS之后,我需要一个页面的内容。我有五台EC2机器,每台都运行selenium,还有我编写的几个scraper实例

然而,我注意到一些非常奇怪的行为。几个小时后,selenium几乎同时在所有机器上停止运行。考虑到我在所有服务器上同时启动selenium和Scraper,这让我相信selenium在长时间运行后会出现一些问题

以下是selenium的日志:

14:34:58.628 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
14:34:58.629 INFO - Version Jetty/5.1.x
14:34:58.630 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
14:34:58.631 INFO - Started HttpContext[/selenium-server,/selenium-server]
14:34:58.631 INFO - Started HttpContext[/,/]
14:34:58.753 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@6a669053
14:34:58.753 INFO - Started HttpContext[/wd,/wd]
14:34:58.764 INFO - Started SocketListener on 0.0.0.0:4444
14:34:58.765 INFO - Started org.openqa.jetty.jetty.Server@2ef36617
21:24:41.031 INFO - Shutting down...
我注意到另一件有趣的事情:在每个集群上,我总是有一个scraper实例出现以下错误:

File "SiteScraper.py", line 238, in _add_rendered_html
    self.browser.get(url)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 168, in get
    self.execute(Command.GET, {'url': url})
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 156, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 147, in check_response
    raise exception_class(message, screen, stacktrace)
WebDriverException: Message: u'Modal dialog present'
我认为这意味着selenium或firefox(我与web驱动程序一起使用的浏览器)会在一段时间后弹出一个模式


有没有人遇到过类似的问题/对如何解决这个问题有什么见解?

当您在机器上启动selenium单机服务器时,请尝试使用java命令的-timeout选项。首先尝试将其设置为非常小的值,以验证它是否导致问题。而不是把它提高到很高的水平

在看到以下内容之后,我将尝试更新java,看看它是否修复了任何问题。