Web Scraper avatar
Web Scraper

No credit card required

View all Actors
Web Scraper

Web Scraper

apify/web-scraper

No credit card required

The scraper of Web

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        // See README for context properties. If the syntax is unfamiliar see the link
23        // https://javascript.info/destructuring-assignment#object-destructuring
24        const { request, log, jQuery } = context;
25    
26        // To be able to use jQuery as $, one needs save it into a variable
27        // and select the inject jQuery option. We've selected it for you.
28        const $ = jQuery;
29        const title = $('title').text();
30    
31        // This is yet another new feature of Javascript called template strings.
32        // https://javascript.info/string#quotes
33        log.info(`URL: ${request.url} TITLE: ${title}`);
34    
35        // To save data just return an object with the requested properties.
36        return {
37            url: request.url,
38            title
39        };
40    },
41    "proxyConfiguration": {
42        "useApifyProxy": false
43    },
44    "initialCookies": [],
45    "waitUntil": [
46        "networkidle2"
47    ],
48    "customData": {}
49};
50
51(async () => {
52    // Run the Actor and wait for it to finish
53    const run = await client.actor("apify/web-scraper").call(input);
54
55    // Fetch and print Actor results from the run's dataset (if any)
56    console.log('Results from dataset');
57    const { items } = await client.dataset(run.defaultDatasetId).listItems();
58    items.forEach((item) => {
59        console.dir(item);
60    });
61})();
Developer
Community logoMaintained by Community
Actor metrics
  • 6 monthly users
  • 99.9% runs succeeded
  • Modified 6 days ago
Categories

You might also like these Actors