Pyppeteer在Linux和Windows上的行为不同 [英] Pyppeteer behaving differently on Linux and Windows

查看:35
本文介绍了Pyppeteer在Linux和Windows上的行为不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有可以四处浏览的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

btw: 我注意到this question has a similar error。但是,错误是不同的(Protocol error (Page.navigate): Target closed而不是Protocol Error (Runtime.callFunctionOn)),环境也不同(node.jsPuppeteer等)。

推荐答案

似乎不再维护Pypepeteer。我遇到了同样的问题,并迁移到工作正常的Selenium

这篇关于Pyppeteer在Linux和Windows上的行为不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆