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://www.amazon.com"
14 }
15 ],
16 "actions": [
17 {
18 "type": "humanActivity"
19 },
20 {
21 "type": "screenshot",
22 "key": "amazon-home"
23 },
24 {
25 "type": "type",
26 "selector": "#twotabsearchtextbox",
27 "value": "mechanical keyboard"
28 },
29 {
30 "type": "click",
31 "selector": "#nav-search-submit-button"
32 },
33 {
34 "type": "wait",
35 "time": 3000
36 },
37 {
38 "type": "screenshot",
39 "key": "amazon-search"
40 },
41 {
42 "type": "humanActivity"
43 },
44 {
45 "type": "scroll",
46 "pages": 2
47 },
48 {
49 "type": "screenshot",
50 "fullPage": true,
51 "key": "amazon-results"
52 },
53 {
54 "type": "javascript",
55 "expression": "(() => { const items = [...document.querySelectorAll('[data-component-type=\"s-search-result\"]')].slice(0, 5).map((el, i) => ({ rank: i+1, title: el.querySelector('h2')?.textContent?.trim(), price: el.querySelector('.a-price .a-offscreen')?.textContent, rating: el.querySelector('.a-icon-alt')?.textContent, url: el.querySelector('h2 a')?.href })); return JSON.stringify(items); })()"
56 },
57 {
58 "type": "extractContent",
59 "format": "text"
60 }
61 ]
62};
63
64
65const run = await client.actor("nocturne/stealth-website-crawler").call(input);
66
67
68console.log('Results from dataset');
69console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
70const { items } = await client.dataset(run.defaultDatasetId).listItems();
71items.forEach((item) => {
72 console.dir(item);
73});
74
75