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(模拟浏览器) 实战
现在有新方法可以搞定这个模拟登陆了&#