mirror of
https://github.com/VinciGit00/Scrapegraph-ai.git
synced 2026-06-20 21:13:05 +08:00
feat: add integration for search on web
This commit is contained in:
parent
67de52a5ba
commit
224ff07032
@ -19,8 +19,22 @@ def search_on_web(
|
||||
timeout: int = 10,
|
||||
proxy: str | dict = None,
|
||||
serper_api_key: str = None,
|
||||
region: str = None,
|
||||
language: str = None,
|
||||
) -> List[str]:
|
||||
"""Search web function with improved error handling and validation"""
|
||||
"""Search web function with improved error handling and validation
|
||||
|
||||
Args:
|
||||
query (str): Search query
|
||||
search_engine (str): Search engine to use
|
||||
max_results (int): Maximum number of results to return
|
||||
port (int): Port for SearXNG
|
||||
timeout (int): Request timeout in seconds
|
||||
proxy (str | dict): Proxy configuration
|
||||
serper_api_key (str): API key for Serper
|
||||
region (str): Country/region code (e.g., 'mx' for Mexico)
|
||||
language (str): Language code (e.g., 'es' for Spanish)
|
||||
"""
|
||||
|
||||
# Input validation
|
||||
if not query or not isinstance(query, str):
|
||||
@ -39,9 +53,31 @@ def search_on_web(
|
||||
try:
|
||||
results = []
|
||||
if search_engine == "google":
|
||||
results = list(
|
||||
google_search(query, num_results=max_results, proxy=formatted_proxy)
|
||||
)
|
||||
|
||||
if region is not None and language is not None:
|
||||
results = list(
|
||||
google_search(
|
||||
query, num_results=max_results, proxy=formatted_proxy,
|
||||
lang= language, region=region)
|
||||
)
|
||||
elif region is not None:
|
||||
results = list(
|
||||
google_search(
|
||||
query, num_results=max_results, proxy=formatted_proxy,
|
||||
region=region)
|
||||
)
|
||||
elif language is not None:
|
||||
results = list(
|
||||
google_search(
|
||||
query, num_results=max_results, proxy=formatted_proxy,
|
||||
lang=language)
|
||||
)
|
||||
else:
|
||||
results = list(
|
||||
google_search(
|
||||
query, num_results=max_results, proxy=formatted_proxy)
|
||||
)
|
||||
print(results)
|
||||
|
||||
elif search_engine == "duckduckgo":
|
||||
research = DuckDuckGoSearchResults(max_results=max_results)
|
||||
|
||||
2
uv.lock
2
uv.lock
@ -3429,7 +3429,7 @@ wheels = [
|
||||
|
||||
[[package]]
|
||||
name = "scrapegraphai"
|
||||
version = "1.35.0"
|
||||
version = "1.36.0"
|
||||
source = { editable = "." }
|
||||
dependencies = [
|
||||
{ name = "async-timeout", version = "4.0.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.12'" },
|
||||
|
||||
Loading…
Reference in New Issue
Block a user