Repository navigation
Expand file tree
/
Copy pathexample.py
More file actions
56 lines (42 loc) · 1.46 KB
/
Copy pathexample.py
File metadata and controls
56 lines (42 loc) · 1.46 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
"""
Perplexity Scraper — Scrapeless LLM Chat Scraper (Python example)
Docs: https://docs.scrapeless.com/en/llm-chat-scraper/quickstart/introduction/
Token: https://app.scrapeless.com/passport/login?redirect=/quick-start
Run:
export SCRAPELESS_API_TOKEN="your_api_token"
pip install requests
python example.py
"""
import os
import json
import requests
API_URL = "https://api.scrapeless.com/api/v2/scraper/execute"
API_TOKEN = os.environ.get("SCRAPELESS_API_TOKEN", "YOUR_API_TOKEN")
payload = {
"actor": "scraper.perplexity",
"input": {
"prompt": "Recommended attractions in New York",
"country": "US",
"web_search": True,
},
# Optional: receive the result via webhook instead of the sync response.
# "webhook": {"url": "https://www.your-webhook.com"},
}
headers = {
"Content-Type": "application/json",
"x-api-token": API_TOKEN,
}
def main():
response = requests.post(API_URL, headers=headers, json=payload, timeout=180)
response.raise_for_status()
data = response.json()
result = data.get("task_result", {})
print("Status: ", data.get("status"))
print("Task ID: ", data.get("task_id"))
print("\nAnswer:\n", result.get("result_text", ""))
for item in result.get("web_results", []) or []:
print(f"- {item.get('name')} -> {item.get('url')}")
# Full response
print("\nRaw response:\n", json.dumps(data, indent=2, ensure_ascii=False))
if __name__ == "__main__":
main()