1import { ApifyClient } from 'apify-client';
2
3
4
5const client = new ApifyClient({
6 token: '<YOUR_API_TOKEN>',
7});
8
9
10const input = {
11 "fixtures": [
12 {
13 "id": "001-rename",
14 "baselineHtml": "<article><span class=\"price\">$10</span></article>",
15 "currentHtml": "<article><span class=\"price-new\">$10</span></article>"
16 },
17 {
18 "id": "002-attribute",
19 "baselineHtml": "<span class=\"offer\" data-price=\"\"></span>",
20 "currentHtml": "<span class=\"offer\">$10</span>"
21 },
22 {
23 "id": "003-duplicate",
24 "baselineHtml": "<span class=\"price\">$10</span>",
25 "currentHtml": "<span class=\"price\">$10</span><span class=\"price\">$10</span>"
26 },
27 {
28 "id": "004-natural",
29 "baselineHtml": "<h1>Blue shoe</h1>",
30 "currentHtml": "<h1>New blue shoe</h1>"
31 }
32 ],
33 "rules": [
34 {
35 "id": "price-selector",
36 "selector": ".price",
37 "mode": "text",
38 "whitespace": "trim",
39 "minMatches": 1,
40 "maxMatches": 1,
41 "fixtureIds": [
42 "001-rename"
43 ]
44 },
45 {
46 "id": "price-attribute",
47 "selector": ".offer",
48 "mode": "attribute",
49 "attribute": "data-price",
50 "whitespace": "preserve",
51 "minMatches": 1,
52 "maxMatches": 1,
53 "fixtureIds": [
54 "002-attribute"
55 ]
56 },
57 {
58 "id": "one-price",
59 "selector": ".price",
60 "mode": "text",
61 "whitespace": "collapse",
62 "minMatches": 1,
63 "maxMatches": 1,
64 "expectedValues": [
65 "$10"
66 ],
67 "fixtureIds": [
68 "003-duplicate"
69 ]
70 },
71 {
72 "id": "title",
73 "selector": "h1",
74 "mode": "text",
75 "whitespace": "collapse",
76 "minMatches": 1,
77 "maxMatches": 1,
78 "fixtureIds": [
79 "004-natural"
80 ]
81 }
82 ]
83};
84
85
86const run = await client.actor("h_murdock/html-selector-fixture-audit").call(input);
87
88
89console.log('Results from dataset');
90console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
91const { items } = await client.dataset(run.defaultDatasetId).listItems();
92items.forEach((item) => {
93 console.dir(item);
94});
95
96