-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathsearch_with_extraction_async.py
More file actions
46 lines (37 loc) · 1.3 KB
/
search_with_extraction_async.py
File metadata and controls
46 lines (37 loc) · 1.3 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
from dotenv import load_dotenv
load_dotenv()
import asyncio
import json
from scrapegraph_py import AsyncScrapeGraphAI
async def main():
async with AsyncScrapeGraphAI() as sgai:
res = await sgai.search(
"best programming languages 2024",
num_results=3,
prompt="Summarize the top programming languages mentioned and why they are recommended",
schema={
"type": "object",
"properties": {
"languages": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"reason": {"type": "string"},
},
},
},
},
},
)
if res.status == "success":
print("=== Search Results ===")
for result in res.data.results:
print(f"\n{result.title}")
print(f"URL: {result.url}")
print("\n=== Extracted Summary ===")
print(json.dumps(res.data.json_data, indent=2))
else:
print("Failed:", res.error)
asyncio.run(main())