pyppeteer setCookie问题

当我使用带有cookie的pyppeteer时,会引发以下异常

文件“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()文件“test.py”,第25行,在主要await page.setCookie(cookies)文件“/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行,发送return await callback pyppeteer.errors.NetworkError:Protocol Error:无效的参数name:string value expected

我的代码列出:

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())

回答(1)

2 years ago

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

添加{'url':“您的网址”,“名称”:“”,“值”:“”}可以解决问题 .