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/catalogue/category/books/travel_2/index.html"
14 }
15 ],
16 "itemSelector": "article.product_pod",
17 "fields": [
18 {
19 "name": "title",
20 "selector": "h3 a",
21 "extract": "attr",
22 "attribute": "title"
23 },
24 {
25 "name": "price",
26 "selector": ".price_color",
27 "regex": "([0-9.]+)",
28 "type": "number"
29 },
30 {
31 "name": "url",
32 "selector": "h3 a",
33 "extract": "attr",
34 "attribute": "href",
35 "type": "url"
36 },
37 {
38 "name": "rating",
39 "selector": "p.star-rating",
40 "extract": "attr",
41 "attribute": "class",
42 "regex": "star-rating (\\w+)"
43 }
44 ],
45 "maxPages": 1,
46 "maxResults": 10,
47 "proxyConfiguration": {
48 "useApifyProxy": false
49 }
50};
51
52
53const run = await client.actor("leadsbrary/selector-map-web-scraper").call(input);
54
55
56console.log('Results from dataset');
57console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
58const { items } = await client.dataset(run.defaultDatasetId).listItems();
59items.forEach((item) => {
60 console.dir(item);
61});
62
63