1from apify_client import ApifyClient
2
3
4
5client = ApifyClient("<YOUR_API_TOKEN>")
6
7
8run_input = {
9 "startUrls": [{ "url": "https://www.amazon.com" }],
10 "actions": [
11 { "type": "humanActivity" },
12 {
13 "type": "screenshot",
14 "key": "amazon-home",
15 },
16 {
17 "type": "type",
18 "selector": "#twotabsearchtextbox",
19 "value": "mechanical keyboard",
20 },
21 {
22 "type": "click",
23 "selector": "#nav-search-submit-button",
24 },
25 {
26 "type": "wait",
27 "time": 3000,
28 },
29 {
30 "type": "screenshot",
31 "key": "amazon-search",
32 },
33 { "type": "humanActivity" },
34 {
35 "type": "scroll",
36 "pages": 2,
37 },
38 {
39 "type": "screenshot",
40 "fullPage": True,
41 "key": "amazon-results",
42 },
43 {
44 "type": "javascript",
45 "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); })()",
46 },
47 {
48 "type": "extractContent",
49 "format": "text",
50 },
51 ],
52}
53
54
55run = client.actor("nocturne/stealth-website-crawler").call(run_input=run_input)
56
57
58print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
59for item in client.dataset(run["defaultDatasetId"]).iterate_items():
60 print(item)
61
62