【问题标题】:Pyppeteer crushes after 20 seconds with pyppeteer.errors.NetworkErrorPyppeteer 在 20 秒后因 pyppeteer.errors.NetworkError 崩溃
【发布时间】:2019-08-06 07:59:34
【问题描述】:

在使用pyppeteer 控制 Chromium 期间,我大约在工作 20 秒后收到错误消息:

pyppeteer.errors.NetworkError: Protocol Error (Runtime.callFunctionOn): Session closed. Most likely the page has been closed.

here 所述,该问题可能是由 python websockets>=7 包的实现及其在 pyppeteer 中的使用引起的。

【问题讨论】:

    标签: python-3.x web-scraping chromium pyppeteer


    【解决方案1】:

    有 3 种解决方案可以防止与 Chromium 断开连接:

    - 修补described here 之类的代码(首选):
    在运行任何其他 Pyppeteer 命令之前运行 sn-p

    def patch_pyppeteer():
        import pyppeteer.connection
        original_method = pyppeteer.connection.websockets.client.connect
    
        def new_method(*args, **kwargs):
            kwargs['ping_interval'] = None
            kwargs['ping_timeout'] = None
            return original_method(*args, **kwargs)
    
        pyppeteer.connection.websockets.client.connect = new_method
    
    patch_pyppeteer()
    

    - 更改trouble making library
    websockets 包降级为websockets-6.0,例如通过 pip3 install websockets==6.0 --force-reinstall(在您的虚拟环境中)

    - 更改代码库pull request 中所述,有望很快合并。

    【讨论】:

      猜你喜欢
      • 2021-04-06
      • 1970-01-01
      • 1970-01-01
      • 2021-10-16
      • 2016-11-03
      • 2020-12-07
      • 1970-01-01
      • 2013-12-23
      • 2020-10-26
      相关资源
      最近更新 更多