1import { ApifyClient } from 'apify-client';
2
3
4
5const client = new ApifyClient({
6 token: '<YOUR_API_TOKEN>',
7});
8
9
10const input = {
11 "urls": [
12 "https://example.com",
13 "https://apify.com"
14 ],
15 "selectors": [
16 {
17 "name": "title",
18 "selector": "h1",
19 "type": "text"
20 },
21 {
22 "name": "canonicalUrl",
23 "selector": "link[rel='canonical']",
24 "type": "attr",
25 "attribute": "href"
26 }
27 ],
28 "firstMatchOnly": true,
29 "maxMatchesPerSelector": 20,
30 "trimWhitespace": true,
31 "maxConcurrency": 5,
32 "pageRange": {
33 "from": 1,
34 "to": 3
35 },
36 "proxyMode": "auto",
37 "proxyConfiguration": {
38 "useApifyProxy": true,
39 "apifyProxyGroups": [
40 "RESIDENTIAL"
41 ]
42 }
43};
44
45
46const run = await client.actor("webdatatools/css-selector-extractor").call(input);
47
48
49console.log('Results from dataset');
50console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
51const { items } = await client.dataset(run.defaultDatasetId).listItems();
52items.forEach((item) => {
53 console.dir(item);
54});
55
56