Generation

generate functionSat, 15 Jul 2023

Function to convert url to pdf with pyppeteer fixed error There is no current event loop

def url_to_pdf(url, pdf_path): """ Function to convert url to pdf with pyppeteer fixed error There is no current event loop :param url: url :param pdf_path: pdf path to save :return: """ loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) loop.run_until_complete(main(url, pdf_path)) def main(url, pdf_path): browser = await launch({'headless': True, 'args': ['--no-sandbox', '--disable-setuid-sandbox']}) page = await browser.newPage() await page.goto(url, {'waitUntil': 'networkidle2'}) await page.pdf({'path': pdf_path, 'format': 'A4'}) await browser.close()

Want to kickstart your project?Use the new AI Studio to create your code