У нас вы можете посмотреть бесплатно How To: Generate PDF in Puppeteer (1 Min) | Convert HTML to PDF или скачать в максимальном доступном качестве, видео которое было загружено на ютуб. Для загрузки выберите вариант из формы ниже:
Если кнопки скачивания не
загрузились
НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если возникают проблемы со скачиванием видео, пожалуйста напишите в поддержку по адресу внизу
страницы.
Спасибо за использование сервиса ClipSaver.ru
In this tutorial, you'll learn how to generate pdf files in Node & Puppeteer. — Facebook: / gokcedbsql — Video Transcript — Hi guys, this is Abhi from Gokcedb. In this video, you're going to learn how to generate a pdf file using puppeteer. Let's start by using the code. On line 8, I'm going to amazon.com and searching for the keyword sunglasses. After waiting one second, I'm using the query selector all method to grab all the product prices and store them in the prices array. Starting in line 21, I'm calculating the average price in the prices array, and then on line 30, I'm asserting that the average price should be greater than 30 dollars. Finally, in online 33 I'm generating a pdf file and save it as wiki.pdf before closing the browser. Next, let's run this program to see what the output looks like. Note, I'm running this program in headless equal to true mode so you won't see a browser window pop up. Looks like the program worked as expected and I see the wiki.pdf file generated. Watch what happens if I change our assertion to expect the average price to be greater than 300 dollars. This time our program failed due to an assertion error. There you have it. Make sure you like, subscribe, and turn on the notification bell until next time. const puppeteer = require('puppeteer'); const expect = require('chai').expect try { (async () =[REMOVED] { const browser = await puppeteer.launch({ headless: true }) const pageObj = await browser.newPage() await pageObj.setViewport({ width: 1280, height: 800 }) await pageObj.goto('https://www.amazon.com/s?k=sunglasses') // Wait 1 second await new Promise(resolve =[REMOVED] setTimeout(resolve, 1000)); // Get the prices let prices = await pageObj.evaluate(() =[REMOVED] { let priceElements = document.querySelectorAll(".a-price-whole") let priceArray = Array.from(priceElements) return priceArray.map(price =[REMOVED] price.textContent.replace('$', '')) }); // Calculate the average price var total = 0; for(var i = 0; i [REMOVED] prices.length; i++) { total += parseFloat(prices[i]); } var avg = total / prices.length; // Assertion console.log('total: ' + total) console.log('average price: ' + avg) expect(avg).to.be.greaterThan(300) // Generate a pdf file await pageObj.pdf({ format: 'A4', path: `wiki.pdf` }) await pageObj.close(); await browser.close(); })() } catch (err) { console.error(err) }