pyppeteer.errors.NetworkError: Protocol Error (Page.navigate): Session closed. Most likely the page

本文介绍了如何解决pyppeteer中的NetworkError,强调它是一个模拟登录的好工具,并提供了实战示例。文章提及了需要的Python库、Chromium下载提示以及在CentOS上的依赖安装。此外,还展示了如何启动浏览器、导航、设置UserAgent、执行JavaScript、处理cookies等操作。
摘要由CSDN通过智能技术生成
def _patch_pyppeteer():
    from typing import Any
    from pyppeteer import connection, launcher
    import websockets.client

    class PatchedConnection(connection.Connection):  # type: ignore
        def __init__(self, *args: Any, **kwargs: Any) -> None:
            super().__init__(*args, **kwargs)
            # the _ws argument is not yet connected, can simply be replaced with another
            # with better defaults.
            self._ws = websockets.client.connect(
                self._url,
                loop=self._loop,
                # the following parameters are all passed to WebSocketCommonProtocol
                # which markes all three as Optional, but connect() doesn't, hence the liberal
                # use of type: ignore on these lines.
                # fixed upstream but not yet released, see aaugustin/websockets#93ad88
                max_size=None,  # type: ignore
                ping_interval=None,  # type: ignore
                ping_timeout=None,  # type: ignore
            )

    connection.Connection = PatchedConnection
    # also imported as a  global in pyppeteer.launcher
    launcher.Connection = PatchedConnection

_patch_pyppeteer()

完美解决  pyppeteer.errors.NetworkError: Protocol Error (Page.navigate): Session closed. Most likely the page has been closed.

完美解决  pyppeteer.errors.NetworkError: Protocol Error (Page.navigate): Session closed. Most likely the page has been closed.

完美解决  pyppeteer.errors.NetworkError: Protocol Error (Page.navigate): Session closed. Most likely the page has been closed.

python爬虫利器 pyppeteer(模拟浏览器) 实战

现在有新方法可以搞定这个模拟登陆了&#

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值