
Scrape Any Website in 3 Steps: URL Code Data (Beginner Template)
Here is a copy-paste template to scrape any website in 3 steps. Step 1: Choose Your URL const URL = " https://example.com/products " ; // Change this Step 2: Copy This Code const cheerio = require ( " cheerio " ); const fs = require ( " fs " ); async function scrape ( url ) { console . log ( `Scraping: ${ url } ` ); const res = await fetch ( url , { headers : { " User-Agent " : " Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " } }); if ( ! res . ok ) { console . error ( `Error: ${ res . status } ` ); return []; } const $ = cheerio . load ( await res . text ()); // CHANGE THESE SELECTORS for your target site const items = []; $ ( " SELECTOR_HERE " ). each (( i , el ) => { items . push ({ title : $ ( el ). find ( " TITLE_SELECTOR " ). text (). trim (), link : $ ( el ). find ( " a " ). attr ( " href " ), // Add more fields as needed }); }); return items ; } async function main () { const data = await scrape ( URL ); console . log ( `Found ${ data . length } items` ); fs . w
Continue reading on Dev.to Tutorial
Opens in a new tab



