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 "proxyMode": "auto",
33 "proxyConfiguration": {
34 "useApifyProxy": true,
35 "apifyProxyGroups": [
36 "RESIDENTIAL"
37 ]
38 }
39};
40
41
42const run = await client.actor("webdatatools/css-selector-extractor").call(input);
43
44
45console.log('Results from dataset');
46console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
47const { items } = await client.dataset(run.defaultDatasetId).listItems();
48items.forEach((item) => {
49 console.dir(item);
50});
51
52