Python scrapy_selenium SeleniumMiddleware 从渲染器返回超时错误

Python scrapy_selenium SeleniumMiddleware returns Timeout error from renderer

提问人:Arman Avetisyan 提问时间:12/20/2022 最后编辑:Arman Avetisyan 更新时间:12/23/2022 访问量:134

问:

我正在使用 scrapy 使用 Selenium Webdriver 运行测试。大多数情况下,脚本工作正常,但有时它会在初始化 SeleniumMiddleware 时返回超时错误。

下面是我的自定义下载中间件,它继承自 SeleniumMiddleware。

class CustomDownloadMiddleware(SeleniumMiddleware):
def __init__(self, *args, **kwargs):

    try:
        super().__init__(*args, **kwargs) # This is where Timeout exception happens
    except Exception as e:
        print("-- Unable initialize Selenium Middleware ---")
        print(e) # This is where it prints the exception message

def process_request(self, request, spider):
    """Process a request using the selenium driver if applicable"""
    ...

以下是我收到的错误消息。

Message: session not created
source-app-1  | from timeout: Timed out receiving message from renderer: 600.000
source-app-1  |   (Session info: headless chrome=102.0.5005.182)

我正在将 Python 与 scrapy、scrapy_selenium 库一起使用,我使用 Chrome 网络驱动程序。 我看到这种失败的比率约为十分之一。

仅供参考...有一个与此问题相关的类似帖子,但对于导致它的原因或如何解决它没有明确的答案。(我已经尝试了那篇帖子中提到的所有可行的解决方案)Selenium 接收来自渲染器的消息超时

更新

我深入研究,当代码启动 Web 驱动程序时,会发生超时异常。Chrome() 类,来自 python 的 selenium 包。

python selenium scrapy selenium-chromedriver chrome-web-driver

评论


答: 暂无答案