Scraper.js Tutorials

Learn to scrape web data efficiently with step-by-step examples

Beginner Tutorials

Extracting Text Content

Learn how to extract text from web pages using simple CSS selectors

>
scraper.get('https://example.com')
.then($ => {
 $('#article-title').text(); 
})
>

Extracting Image URLs

Discover how to extract image source URLs from web pages

>
scraper.get('https://example.com')
.then($ => {
 $("img[src]").map((i, img) => $(img).attr("src"));
})
>

Intermediate Tutorials

Extracting Multiple Elements

How to extract content from multiple elements at once using arrays

>
scraper.get('https://example.com')
.then($ => {
 $('.product').map((i, item) => ({
 name: $('.title', item).text(),
 price: $('.price', item).text()
 }));
})
>

Pagination Handling

Best practices for extracting data from sites with multiple pages

>
async function scrapeAllPages(baseUrl) {
 const pages = 5;
 let results = [];
 
 for (let i = 1; i  <= pages; i++) {
 let currentPage = await scraper.get(`${baseUrl}?page=${i}`);
 // extract data and add to results
 }
 
 return results;
}
>

Advanced Tutorials

Handling JavaScript-rendered Content

Extracting content from sites that generate content via JavaScript

>
scraper.get('https://example.com', true)
.then(browser => {
 const page = browser.newPage();
 await page.goto('https://example.com');
 return page.evaluate(() => document.body.innerHTML);
});
>

Error Handling

Best practices for handling common API and network errors

>
scraper.get('https://example.com')
.then($ => {
 // success handling
})
.catch(err => {
 // error handling
});
>

Need Help??

Stuck on a tutorial or need help with your project? Check our documentation or reach out on GitHub!!