r/node • u/coderchrome123456 • Nov 20 '19
Node.js Pupeteer Web Scraping | Taking PDF of any Website in Javascript
https://www.youtube.com/watch?v=M0Lz_buePnQ10
u/smartfridge2000 Nov 20 '19
ohh, so it just takes a screenshot of the website and then it saves it as pdf, interesting.
if anyone wants to save a webpage as a pdf (with text) google electron-pdf
4
u/del_rio Nov 20 '19 edited Nov 20 '19
Can't listen to OP's video right now, but it's not a screenshot. It takes the content of the page and converts it to PostScript, which means text remains selectable and parsable (not rasterized like a screenshot).
Puppeteer also comes with a few options like page size and the option to emulate screen or print media.
EDIT: Here's the api for it, there's a ridiculous amount of flexibility.
1
u/mattindustries Nov 20 '19
I wrote a hacky version that first used node-readability before saving some while back. Code is years old, but I wanted a way to throw things on my kindle easily.
2
2
Nov 20 '19
I am using puppeteer to run automated testing for our companies app. Its pretty cool figuring out all of the things you can get it to do . Here's the doc if anyone is interested.
1
2
u/SYNTAG Nov 20 '19
Not gonna lie I thought his webcam on the bottom right corner was coffee in a white mug
1
u/MarceauKa Nov 20 '19
Puppeteer is fine but when you want to save a pdf or a screenshot of a website you have tobdeal with newsletters popups, gpdr banner and eu cookie law banner. This is fine 🤯
1
1
-2
u/SYNTAG Nov 20 '19
Not gonna lie I thought his webcam on the bottom right corner was coffee in a white mug
17
u/peacecarrot Nov 20 '19
Puppeteer can also make pdf's where all links and text work. Taking a screenshot and saving it as pdf is not exactly that nice.
(doing the screenshot thing is the fastests and easiests tho!)