1

当我将 pyppeteer 与 cookie 一起使用时,会引发以下异常

文件“test.py”,第 33 行,在 asyncio.get_event_loop().run_until_complete(main())

文件“/usr/local/python3.6/lib/python3.6/asyncio/base_events.py”,第 468 行,在 run_until_complete 返回 future.result()

主要等待 page.setCookie(cookies) 中的文件“test.py”,第 25 行

文件“/usr/local/python3.6/lib/python3.6/site-packages/pyppeteer/page.py”,第 392 行,在 setCookie 中等待 self.deleteCookie(*items)

文件“/usr/local/python3.6/lib/python3.6/site-packages/pyppeteer/page.py”,第 373 行,在 deleteCookie 中等待 self._client.send('Network.deleteCookies', item)

文件“/usr/local/python3.6/lib/python3.6/site-packages/pyppeteer/connection.py”,第 200 行,在发送返回等待回调

pyppeteer.errors.NetworkError:协议错误:无效参数名称:应为字符串值

我列出的代码:

async def main():
    cookies = {'name': "", 'name2': ""}  # just a example
    browser = await launch({"executablePath": "/usr/bin/google-chrome-stable"}, args=['--no-sandbox'], headless=True)
    page = await browser.newPage()
    await page.setCookie(cookies)
    print('after set cookie')
    response = await page.goto('http://example.com/', timeout=100000)

    print('before screenshot')
    await page.screenshot({'path': '/tmp/tmp.png', 'quality': 100, 'fullPage': True})
    await browser.close()

asyncio.get_event_loop().run_until_complete(main())
4

1 回答 1

2

根据项目github:https ://github.com/miyakogi/pyppeteer/issues/94

添加 {'url': "your url", 'name': "", 'value': ""} 可以解决问题。

于 2018-07-08T05:47:08.450 回答