我有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机器上启动它时,无论是否有导航,它都从OK(确定)开始。然后,单击几次导航后,我超时,然后出现另一个错误:
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
。
顺便说一句:
我注意到了this question has a similar error。但是,错误和环境(Protocol error (Page.navigate): Target closed
,Protocol Error (Runtime.callFunctionOn)
等)不同(错误由node.js
代替Puppeteer
)。