-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathsearch_with_extraction.py
More file actions
41 lines (34 loc) · 1007 Bytes
/
search_with_extraction.py
File metadata and controls
41 lines (34 loc) · 1007 Bytes
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
from dotenv import load_dotenv
load_dotenv()
import json
from scrapegraph_py import ScrapeGraphAI
sgai = ScrapeGraphAI()
res = 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)