如何修复 pyppeteer.errors.NetworkError: Request interception is not enabled.
*注意:*另请参见Pyppeteer 最小网络请求拦截示例
问题:
你正在尝试使用以下命令在 Pyppeteer 中拦截请求
pyppeteer_request_interception_enable.py
page.on('request', my_intercept_request)但你得到类似这样的错误消息:
pyppeteer_traceback.txt
Traceback (most recent call last):
File "/usr/lib/python3.6/asyncio/events.py", line 145, in _run
self._callback(*self._args)
File "/usr/local/lib/python3.6/dist-packages/pyee/_compat.py", line 62, in _callback
self.emit('error', exc)
File "/usr/local/lib/python3.6/dist-packages/pyee/_base.py", line 106, in emit
self._emit_handle_potential_error(event, args[0] if args else None)
File "/usr/local/lib/python3.6/dist-packages/pyee/_base.py", line 83, in _emit_handle_potential_error
raise error
File "run.py", line 6, in intercept
await request.continue_()
File "/usr/local/lib/python3.6/dist-packages/pyppeteer/network_manager.py", line 481, in continue_
raise NetworkError('Request interception is not enabled.')
pyppeteer.errors.NetworkError: Request interception is not enabled.解决方案
添加
enable_request_interception_fix.py
await page.setRequestInterception(True)直接在你调用
enable_request_interception.py
page = await browser.newPage()这将启用请求拦截,你的代码将正常运行。
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow