Pyppeteer在Linux和Windows上的行为有所不同

时间:2018-12-25 09:37:19

标签: python-3.x google-chrome-devtools python-asyncio puppeteer pyppeteer

我有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 closedProtocol Error (Runtime.callFunctionOn)等)不同(错误由node.js代替Puppeteer)。

0 个答案:

没有答案