#🔒 pyppeteer code won't work

12 messages · Page 1 of 1 (latest)

wanton storm
#
import asyncio
from pyppeteer import launch

async def main():
    browser = await launch()
    page = await browser.newPage()
    await page.goto('https://quotes.toscrape.com/')
    await page.screenshot({'path': 'screenshot.png'})
    await browser.close()

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

Error:

/home/abdu/Downloads/test.py:13: DeprecationWarning: There is no current event loop
  asyncio.get_event_loop().run_until_complete(main())
rough shellBOT
#

@wanton storm

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

radiant fern
#

Is that the complete code?

warm echo
#

From python 3.11 onwards, asyncio doesn't automatically create a loop for you. You can easily start your own though:

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
#

so your code becomes:

import asyncio
from pyppeteer import launch

async def main():
    browser = await launch()
    page = await browser.newPage()
    await page.goto('https://quotes.toscrape.com/')
    await page.screenshot({'path': 'screenshot.png'})
    await browser.close()

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

loop.run_until_complete(main())```
radiant fern
#

I'm not sure that's all their code. The error was on line 13 and they only pasted 11 lines

#

Perhaps they can adapt your solution though.

warm echo
#

Yeah, that code is probably unrelated to the problem, or contains login credentials, or whatever else

radiant fern
#

maybe

rough shellBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.