8

我有一个脚本使用了我正在运行的无头浏览器,使用crontab -e。它运行正常第几次,然后用下面的回溯崩溃:无头脚本在几次运行后崩溃

Traceback (most recent call last): 
    File "/home/clint-selenium-firefox.py", line 83, in <module> 
    driver.get(url) 
    File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 248, in get 
    self.execute(Command.GET, {'url': url}) 
    File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute 
    self.error_handler.check_response(response) 
    File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response 
    raise exception_class(message, screen, stacktrace) 
selenium.common.exceptions.WebDriverException: Message: Failed to decode response from marionette 

我的crontab行是:

*/10 * * * * export DISPLAY=:0 && python /home/clint-selenium-firefox.py >> /home/error.log 2>&1 

我不想让我受够了这种python脚本超负荷此拿出我认为是相关的部分。

from pyvirtualdisplay import Display 

display = Display(visible=0, size=(800, 600)) 
display.start() 
... 
driver = webdriver.Firefox() 
driver.get(url) 
... 
driver.quit() 
... 
display.stop() 

您的帮助是非常感谢。

编辑

版本:火狐49.0.2;硒:3.0.1; geckodriver:geckodriver-v0.11.1-linux64.tar.gz

左右误差(上driver.get(url)失败)代码:

driver = webdriver.Firefox() 
if DEBUG: print "Opened Firefox" 

for u in urls: 
    list_of_rows = [] 
    list_of_old_rows = [] 

    # get the old version of the site data 
    mycsvfile = u[1] 
    try: 
     with open(mycsvfile, 'r') as csvfile: 
      old_data = csv.reader(csvfile, delimiter=' ', quotechar='|') 
      for o in old_data: 
       list_of_old_rows.append(o) 
    except: pass 

    # get the new data 
    url = u[0] 
    if DEBUG: print url  

    driver.get(url) 
    if DEBUG: print driver.title 
    time.sleep(1) 
    page_source = driver.page_source 
    soup = bs4.BeautifulSoup(page_source,'html.parser') 
+0

我已经做了很多或阅读此。我需要使用木偶吗? – HenryM

+0

什么是您使用的firefox,selenium和geckodriver版本? –

+0

在每种情况下,我正在下载最新版本 – HenryM

回答

6

Multiple Firefox instances failing with NS_ERROR_SOCKET_ADDRESS_IN_USE #99这是因为没有--marionette端口选项传递给geckodriver - 这意味着geckodriver的所有实例启动firefox传递相同的期望的默认端口(2828)。第一个firefox实例绑定到该端口,未来的实例不能和所有的geckodriver实例最终连接到第一个firefox实例 - 这会产生各种不可预知的行为。

跟着:我认为一个合理的短期解决方案是做其他司机正在做的事情,并要求木偶绑定到由geckodriver生成的随机自由端口。目前它使用2828作为其产生的所有Firefox实例的默认值。 由于Marionette遗憾的是还没有将端口传回给客户端(geckodriver)的带外方式,这本质上是活泼的,但我们可以通过来自bug 1240830的提案之一来改进未来的情况。

change

Selenium 3.0.0.b2 
* Updated Marionette port argument to match other drivers. 

做我猜随机只能这么久。提高issue。代码修复可能需要您拥有的硒,firefox和geckodriver版本。您可以放弃使用Selenium 2.53.0和firefox esr 38.8,直到解决问题。你的来电。

UPDATE:尝试

from selenium import webdriver 
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary 

binary = FirefoxBinary('path/to/binary') 
driver = webdriver.Firefox(firefox_binary=binary) 
+0

我正在尝试返回到早期版本。安装硒2.53.0很容易,但我努力得到Firefox的ESR 38.8。我想'sudo apt-get install iceweasel',它只是选择和安装最新版本的Firefox。你能建议如何强制旧版本。 – HenryM

+0

我已经设法回到你提出的版本,但我现在得到'OSError:[Errno 13] Permission denied' – HenryM

+0

在linux上,我打开了我的google chrome浏览器并键入https://download.mozilla.org /?product=firefox-38.8.0esr-SSL&os=linux&lang=ach – MikeJRamsey56