How to copy raw text from website without using clipboard

Viewed 180

I have made a scraper with puppeteer which goes to a website presses Ctrl+A and Ctrl+C and copies the text to a file.

Its a very simple script but it is very annoying that it uses the windows clipboard because if I let the script run in the background I cannot copy and paste anything.

Is there another way to copy the raw text from websites without using the windows clipboard? With raw text I mean all the text which you can see when you visit a website and press Ctrl+A.

1 Answers

You can get the innerText value from document.body, which should contain the same (or at least very similar text) to what Ctrl+A, Ctrl+C would give you.

Code Sample

const text = await page.evaluate(() => document.body.innerText);
Related