Web scraping in Node.js, step by step
Fetch the page. Node 18 and newer have fetch built in. No axios needed.
Check the source, not DevTools. The Elements tab shows the page after JavaScript ran. View source shows what fetch gets. Search there for your value.
Pick the value. cheerio gives you jQuery-style selectors on the server. For JSON inside the page (JSON-LD, __NEXT_DATA__), JSON.parse beats any selector.
Limit how many run at once. Promise.all on ten thousand links is a small attack. Run a few at a time, with a pause.
cheerio, Puppeteer or Playwright?
cheerio. Parses HTML and runs no scripts. Milliseconds a page.
Puppeteer and Playwright. Drive a real Chrome. For pages built in the browser, and for clicks. Seconds and hundreds of MB a page.
In the browser itself. A snippet in the console or a userscript is fine for the one page you are looking at, not for a crawl.
Scraping JavaScript-rendered pages without a browser
A page that renders in the browser still gets its data from somewhere. Often it sits in the HTML as a JSON blob, or the page calls a JSON URL you can see in the network tab (check the terms before you use it). Either is faster and steadier than waiting for a headless browser to paint.
A free JavaScript script with nothing to install
The script generator writes one extract.mjs for Node 18 or newer, with no packages: a rule per field, backups for each, and for every value how sure it is. Import extract(html) into your own code, or run the file on a list of links or a sitemap.
- Cut web scraping costs: stop paying an AI per page
- Free web scraping script generator
- You probably don't need a headless browser
- Web scraping with Python
- Try it on your own pages
Tested on 207 real pages from 49 sites: 609 of 659 values exactly right, 0 wrong. The rest came back as not found, unsure or in another format.
Made by Simon. I have been scraping for more than five years and building software since 2015.