
Cheerio Scraper
Pricing
Pay per usage

Cheerio Scraper
Crawls websites using raw HTTP requests, parses the HTML with the Cheerio library, and extracts data from the pages using a Node.js code. Supports both recursive crawling and lists of URLs. This actor is a high-performance alternative to apify/web-scraper for websites that do not require JavaScript.
4.7 (11)
Pricing
Pay per usage
137
Total users
7.5k
Monthly users
779
Runs succeeded
>99%
Last modified
16 days ago
You can access the Cheerio Scraper programmatically from your own applications by using the Apify API. You can also choose the language preference from below. To use the Apify API, you’ll need an Apify account and your API token, found in Integrations settings in Apify Console.
1import { ApifyClient } from 'apify-client';2
3// Initialize the ApifyClient with your Apify API token4// Replace the '<YOUR_API_TOKEN>' with your token5const client = new ApifyClient({6 token: '<YOUR_API_TOKEN>',7});8
9// Prepare Actor input10const input = {11 "startUrls": [12 {13 "url": "https://crawlee.dev/js"14 }15 ],16 "respectRobotsTxtFile": true,17 "globs": [18 {19 "glob": "https://crawlee.dev/js/*/*"20 }21 ],22 "pseudoUrls": [],23 "excludes": [24 {25 "glob": "/**/*.{png,jpg,jpeg,pdf}"26 }27 ],28 "linkSelector": "a[href]",29 "pageFunction": async function pageFunction(context) {30 const { $, request, log } = context;31 32 // The "$" property contains the Cheerio object which is useful33 // for querying DOM elements and extracting data from them.34 const pageTitle = $('title').first().text();35 36 // The "request" property contains various information about the web page loaded. 37 const url = request.url;38 39 // Use "log" object to print information to Actor log.40 log.info('Page scraped', { url, pageTitle });41 42 // Return an object with the data extracted from the page.43 // It will be stored to the resulting dataset.44 return {45 url,46 pageTitle47 };48 },49 "proxyConfiguration": {50 "useApifyProxy": true51 },52 "initialCookies": [],53 "additionalMimeTypes": [],54 "preNavigationHooks": `// We need to return array of (possibly async) functions here.55 // The functions accept two arguments: the "crawlingContext" object56 // and "requestAsBrowserOptions" which are passed to the `requestAsBrowser()`57 // function the crawler calls to navigate..58 [59 async (crawlingContext, requestAsBrowserOptions) => {60 // ...61 }62 ]`,63 "postNavigationHooks": `// We need to return array of (possibly async) functions here.64 // The functions accept a single argument: the "crawlingContext" object.65 [66 async (crawlingContext) => {67 // ...68 },69 ]`,70 "customData": {}71};72
73// Run the Actor and wait for it to finish74const run = await client.actor("apify/cheerio-scraper").call(input);75
76// Fetch and print Actor results from the run's dataset (if any)77console.log('Results from dataset');78console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);79const { items } = await client.dataset(run.defaultDatasetId).listItems();80items.forEach((item) => {81 console.dir(item);82});83
84// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs
Cheerio Scraper - HTML scraping tool API in JavaScript
The Apify API client for JavaScript is the official library that allows you to use Cheerio Scraper API in JavaScript or TypeScript, providing convenience functions and automatic retries on errors.
Install the apify-client
$npm install apify-client
Other API clients include: