错误原因:pyppeteer框架为异步,为此内部延迟方法也必须使用异步,否则会抛出此错误
future: <Future finished exception=NetworkError('Protocol error (Target.detachFromTarget): No session with given id')
参考:https://github.com/pyppeteer/pyppeteer/issues/89
参考https://github.com/ranksense/url-inspector-automator/issues/1
官方解决方案:https://github.com/miyakogi/pyppeteer/issues/194
错误代码:
if some:
do something
else:
try:
do something
except Exception:
do something
time.sleep(0.5)
try:
do something
except Exception:
pass
修改后的代码【这里的延迟必须是异步延迟方法,这里time.sleep会此报错】:
if some: do something else: try: do something except Exception: do something
await asyncio.sleep(0.5) # or await page.waitFor(10)
try: do something except Exception: pass