1import { ApifyClient } from 'apify-client';
2
3
4
5const client = new ApifyClient({
6 token: '<YOUR_API_TOKEN>',
7});
8
9
10const input = {
11 "startUrls": [
12 {
13 "url": "https://books.toscrape.com/"
14 }
15 ],
16 "recordSelector": "article.product_pod",
17 "fields": [
18 {
19 "name": "title",
20 "selector": "h3 a",
21 "source": "attribute",
22 "attribute": "title",
23 "type": "string",
24 "required": true
25 },
26 {
27 "name": "price",
28 "selector": ".price_color",
29 "type": "number",
30 "pattern": "([0-9.]+)",
31 "required": true
32 },
33 {
34 "name": "productUrl",
35 "selector": "h3 a",
36 "source": "attribute",
37 "attribute": "href",
38 "type": "url",
39 "required": true
40 }
41 ],
42 "maxItems": 20
43};
44
45
46const run = await client.actor("automation-lab/schema-guided-web-data-to-excel").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