我有pyppeteer
可以浏览的代码。假设它只点击a
标签。
它在我的本地 Windows 机器上运行良好,但每当我在 Linux 服务器上远程运行它时就会中断。相同conda env
,相同的代码。
我的代码的相关部分经过简化,如下所示:
async def act(self):
element = self.element
async def get_action():
tag_name = await self.page.evaluate(
'elem => { return elem.tagName.toLowerCase(); }',
element)
action = None
if tag_name == 'a':
action = element.click()
else:
action = async_pass()
return action
async def get_action_future():
# gather syntax based on:
# https://miyakogi.github.io/pyppeteer/reference.html#pyppeteer.page.Page.click
action = await get_action()
future_action = asyncio.gather(
action,
asyncio.sleep(0.001), # dirty, dirty work-around, doesn't work nicely otherwise
)
waited_future = await asyncio.shield(future_action)
if waited_future[0] is None:
await self.page.waitForNavigation(self.wait_options)
return None
await get_action_future()
它在我的 Windows 机器上运行良好。当我在 Linux 机器上启动它时,它启动正常,无论是否有导航。然后,在几次导航点击后,我得到一个超时,然后是另一个错误:
Error encountered: Navigation Timeout Exceeded: 20000 ms exceeded.
# then I trigger the element selector and the act method again, wrapped in try/except
Error encountered: Protocol Error (Runtime.callFunctionOn): Session closed. Most likely the page has been closed.
我在这个问题上停留了一段时间,不胜感激!
我的环境包括:
python=3.6, pyppeteer=0.0.25
.
顺便说一句:我注意到这个问题有一个类似的错误。但是,错误是不同的(Protocol error (Page.navigate): Target closed
而不是Protocol Error (Runtime.callFunctionOn)
),以及环境(node.js
,Puppeteer
等)。