-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
59 lines (50 loc) · 1.62 KB
/
Copy pathexample.js
File metadata and controls
59 lines (50 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* ChatGPT Scraper — Scrapeless LLM Chat Scraper (Node.js example)
*
* Docs: https://docs.scrapeless.com/en/llm-chat-scraper/quickstart/introduction/
* Token: https://app.scrapeless.com/passport/login?redirect=/quick-start
*
* Run (Node.js 18+, uses the built-in fetch):
* export SCRAPELESS_API_TOKEN="your_api_token"
* node example.js
*/
const API_URL = "https://api.scrapeless.com/api/v2/scraper/execute";
const API_TOKEN = process.env.SCRAPELESS_API_TOKEN || "YOUR_API_TOKEN";
const payload = {
actor: "scraper.chatgpt",
input: {
prompt: "Most reliable proxy service for data extraction",
country: "US",
web_search: true,
shopping: false,
},
// Optional: receive the result via webhook instead of the sync response.
// webhook: { url: "https://www.your-webhook.com" },
};
async function main() {
const response = await fetch(API_URL, {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-token": API_TOKEN,
},
body: JSON.stringify(payload),
});
if (!response.ok) {
throw new Error(`Request failed: ${response.status} ${await response.text()}`);
}
const data = await response.json();
const result = data.task_result || {};
console.log("Status: ", data.status);
console.log("Task ID:", data.task_id);
console.log("Model: ", result.model);
console.log("\nAnswer:\n", result.result_text || "");
for (const link of result.search_result || []) {
console.log(`- ${link.title} -> ${link.url}`);
}
console.log("\nRaw response:\n", JSON.stringify(data, null, 2));
}
main().catch((err) => {
console.error(err);
process.exit(1);
});