My Actr testing 2 avatar
My Actr testing 2
Try for free

No credit card required

View all Actors
My Actr testing 2

My Actr testing 2

xrhibiyftd/my-actr-testing-2
Try for free

No credit card required

Crawls websites with the headless Chrome and Puppeteer library using a provided server-side Node.js code. This crawler is an alternative to apify/web-scraper that gives you finer control over the process. Supports both recursive crawling and list of URLs. Supports login to website.

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 your Apify 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://crawlee.dev"
13        }
14    ],
15    "globs": [
16        {
17            "glob": "https://crawlee.dev/*/*"
18        }
19    ],
20    "pseudoUrls": [],
21    "excludes": [
22        {
23            "glob": "/**/*.{png,jpg,jpeg,pdf}"
24        }
25    ],
26    "linkSelector": "a",
27    "pageFunction": async function pageFunction(context) {
28        const { page, request, log } = context;
29        const title = await page.title();
30        log.info(`URL: ${request.url} TITLE: ${title}`);
31        return {
32            url: request.url,
33            title
34        };
35    },
36    "proxyConfiguration": {
37        "useApifyProxy": true
38    },
39    "initialCookies": [],
40    "waitUntil": [
41        "networkidle2"
42    ],
43    "preNavigationHooks": `// We need to return array of (possibly async) functions here.
44        // The functions accept two arguments: the "crawlingContext" object
45        // and "gotoOptions".
46        [
47            async (crawlingContext, gotoOptions) => {
48                const { page } = crawlingContext;
49                // ...
50            },
51        ]`,
52    "postNavigationHooks": `// We need to return array of (possibly async) functions here.
53        // The functions accept a single argument: the "crawlingContext" object.
54        [
55            async (crawlingContext) => {
56                const { page } = crawlingContext;
57                // ...
58            },
59        ]`,
60    "customData": {}
61};
62
63(async () => {
64    // Run the Actor and wait for it to finish
65    const run = await client.actor("xrhibiyftd/my-actr-testing-2").call(input);
66
67    // Fetch and print Actor results from the run's dataset (if any)
68    console.log('Results from dataset');
69    const { items } = await client.dataset(run.defaultDatasetId).listItems();
70    items.forEach((item) => {
71        console.dir(item);
72    });
73})();
Developer
Author's avatar
Community logoMaintained by Community
Actor metrics
  • 86 monthly users
  • 89.7% runs succeeded
  • Created in Jan 2024
  • Modified about 1 month ago
Categories

You might also like these Actors