gpt4 book ai didi

python - Python/Firefox headless 抓取脚本中的 "Failed to decode response from marionette"消息

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

美好的一天,我在这里和谷歌上进行了大量搜索,但尚未找到解决此问题的解决方案。

场景是:

我有一个 Python 脚本 (2.7),它循环访问许多 URL(例如,想想亚马逊页面、抓取评论)。每个页面都有相同的 HTML 布局,只是抓取不同的信息。我将 Selenium 与 headless 浏览器一起使用,因为这些页面具有需要执行以获取信息的 javascript。

我在我的本地机器 (OSX 10.10) 上运行这个脚本。 Firefox 是最新的 v59。 Selenium 的版本为 3.11.0,使用的是 geckodriver v0.20。

此脚本在本地没有问题,它可以遍历所有 URL 并毫无问题地抓取页面。

现在,当我将脚本放在我的服务器上时,唯一的区别是它是 Ubuntu 16.04(32 位)。我使用适当的 geckodriver(仍然是 v0.20),但其他一切都是一样的(Python 2.7,Selenium 3.11)。它似乎使 headless 浏览器随机崩溃,然后所有 browserObjt.get('url...') 不再工作。

错误消息说:

Message: failed to decode response from marionette

对页面的任何进一步的 selenium 请求都会返回错误:

Message: tried to run command without establishing a connection


显示一些代码:

当我创建驱动程序时:

    options = Options()
options.set_headless(headless=True)

driver = webdriver.Firefox(
firefox_options=options,
executable_path=config.GECKODRIVER
)

driver 作为参数 browserObj 传递给脚本的函数,然后用于调用特定页面,然后一旦加载它就传递给 BeautifulSoup 进行解析:

browserObj.get(url)

soup = BeautifulSoup(browserObj.page_source, 'lxml')

错误可能指向导致浏览器崩溃的 BeautifulSoup 行。

这可能是什么原因造成的,我该怎么做才能解决这个问题?


编辑:添加指向同一事物的堆栈跟踪:

Traceback (most recent call last):
File "main.py", line 164, in <module>
getLeague
File "/home/ps/dataparsing/XXX/yyy.py", line 48, in BBB
soup = BeautifulSoup(browserObj.page_source, 'lxml')
File "/home/ps/AAA/projenv/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 670, in page_source
return self.execute(Command.GET_PAGE_SOURCE)['value']
File "/home/ps/AAA/projenv/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "/home/ps/AAA/projenv/local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
WebDriverException: Message: Failed to decode response from marionette

注意:此脚本用于 Chrome。因为服务器是32位服务器,我只能用chromedriver v0.33,只支持Chrome v60-62。目前 Chrome 是 v65,在 DigitalOcean 上我似乎没有简单的方法可以恢复到旧版本 - 这就是我坚持使用 Firefox 的原因。

最佳答案

对于在 Docker 容器中运行 selenium webdriver 时遇到此问题的任何其他人,increasing the container size to 2gb修复 this issue .

如果 OP 通过将他们的服务器 RAM 升级到 2Gb 解决了他们的问题,我想这也会影响物理机器,但这可能是巧合。

关于python - Python/Firefox headless 抓取脚本中的 "Failed to decode response from marionette"消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49734915/

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