A template for scraping data from a single web page in TypeScript (Node.js). The URL of the web page is passed in via input, which is defined by the input schema. The template uses the Axios client to get the HTML of the page and the Cheerio library to parse the data from it. The data are then stored in a dataset where you can easily access them.
The scraped data in this template are page headings but you can easily edit the code to scrape whatever you want from the page.
- Apify SDK - a toolkit for building Actors
- Input schema - define and easily validate a schema for your Actor's input
- Dataset - store structured data where each object stored has the same attributes
- Axios client - promise-based HTTP Client for Node.js and the browser
- Cheerio - library for parsing and manipulating HTML and XML
-
Actor.getInput()
gets the input where the page URL is defined -
axios.get(url)
fetches the page -
cheerio.load(response.data)
loads the page data and enables parsing the headings -
This parses the headings from the page and here you can edit the code to parse whatever you need from the page
$("h1, h2, h3, h4, h5, h6").each((_i, element) => {...});
-
Actor.pushData(headings)
stores the headings in the dataset
- Web scraping in Node.js with Axios and Cheerio
- Web scraping with Cheerio in 2023
- Video tutorial on building a scraper using CheerioCrawler
- Written tutorial on building a scraper using CheerioCrawler
- Integration with Zapier, Make, Google Drive, and others
- Video guide on getting scraped data using Apify API
- A short guide on how to build web scrapers using code templates: