Skip to content

Commit 224ff07

Browse files
committed
feat: add integration for search on web
1 parent 67de52a commit 224ff07

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

scrapegraphai/utils/research_web.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,22 @@ def search_on_web(
1919
timeout: int = 10,
2020
proxy: str | dict = None,
2121
serper_api_key: str = None,
22+
region: str = None,
23+
language: str = None,
2224
) -> List[str]:
23-
"""Search web function with improved error handling and validation"""
25+
"""Search web function with improved error handling and validation
26+
27+
Args:
28+
query (str): Search query
29+
search_engine (str): Search engine to use
30+
max_results (int): Maximum number of results to return
31+
port (int): Port for SearXNG
32+
timeout (int): Request timeout in seconds
33+
proxy (str | dict): Proxy configuration
34+
serper_api_key (str): API key for Serper
35+
region (str): Country/region code (e.g., 'mx' for Mexico)
36+
language (str): Language code (e.g., 'es' for Spanish)
37+
"""
2438

2539
# Input validation
2640
if not query or not isinstance(query, str):
@@ -39,9 +53,31 @@ def search_on_web(
3953
try:
4054
results = []
4155
if search_engine == "google":
42-
results = list(
43-
google_search(query, num_results=max_results, proxy=formatted_proxy)
44-
)
56+
57+
if region is not None and language is not None:
58+
results = list(
59+
google_search(
60+
query, num_results=max_results, proxy=formatted_proxy,
61+
lang= language, region=region)
62+
)
63+
elif region is not None:
64+
results = list(
65+
google_search(
66+
query, num_results=max_results, proxy=formatted_proxy,
67+
region=region)
68+
)
69+
elif language is not None:
70+
results = list(
71+
google_search(
72+
query, num_results=max_results, proxy=formatted_proxy,
73+
lang=language)
74+
)
75+
else:
76+
results = list(
77+
google_search(
78+
query, num_results=max_results, proxy=formatted_proxy)
79+
)
80+
print(results)
4581

4682
elif search_engine == "duckduckgo":
4783
research = DuckDuckGoSearchResults(max_results=max_results)

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)