Cheerio Scraper avatar
Cheerio Scraper

No credit card required

View all Actors
Cheerio Scraper

Cheerio Scraper

apify/cheerio-scraper

No credit card required

The code examples below show how to run the Actor and get its results. To run the code, you need to have an Apify account. Replace <YOUR_API_TOKEN> in the code with your API token, which you can find under Settings > Integrations in Apify Console. Learn mode

Node.js

Python

curl

1import { ApifyClient } from 'apify-client';
2
3// Initialize the ApifyClient with API token
4const client = new ApifyClient({
5    token: '<YOUR_API_TOKEN>',
6});
7
8// Prepare Actor input
9const input = {
10    "startUrls": [
11        {
12            "url": "https://apify.com"
13        }
14    ],
15    "pseudoUrls": [
16        {
17            "purl": "https://apify.com[(/[\\w-]+)?]"
18        }
19    ],
20    "linkSelector": "a",
21    "pageFunction": async function pageFunction(context) {
22        const { $, request, log } = context;
23        const title = $('title').text();
24        log.info(`URL: ${request.url} TITLE: ${title}`);
25        return {
26            url: request.url,
27            title
28        };
29    },
30    "proxyConfiguration": {
31        "useApifyProxy": false
32    },
33    "initialCookies": []
34};
35
36(async () => {
37    // Run the Actor and wait for it to finish
38    const run = await client.actor("apify/cheerio-scraper").call(input);
39
40    // Fetch and print Actor results from the run's dataset (if any)
41    console.log('Results from dataset');
42    const { items } = await client.dataset(run.defaultDatasetId).listItems();
43    items.forEach((item) => {
44        console.dir(item);
45    });
46})();
Developer
Community logoMaintained by Community
Actor metrics
  • 1 monthly users
  • 100.0% runs succeeded
  • Modified about 5 years ago
Categories

You might also like these Actors