1- """
1+ """
22Module for making the request on the web
33"""
44import re
55from typing import List
66from langchain_community .tools import DuckDuckGoSearchResults
7- from googlesearch import search
7+ from googlesearch import search as google_search
8+ from yahoo_search import search as yahoo_search
89
910
1011def search_on_web (query : str , search_engine : str = "Google" , max_results : int = 10 ) -> List [str ]:
@@ -29,18 +30,29 @@ def search_on_web(query: str, search_engine: str = "Google", max_results: int =
2930 This function allows switching between Google and DuckDuckGo to perform internet searches, returning a list of result URLs.
3031 """
3132
32- if search_engine == "Google " :
33+ if search_engine . lower () == "google " :
3334 res = []
3435
35- for url in search (query , stop = max_results ):
36+ for url in google_search (query , stop = max_results ):
3637 res .append (url )
3738 return res
38- elif search_engine == "DuckDuckGo " :
39+ elif search_engine . lower () == "duckduckgo " :
3940 research = DuckDuckGoSearchResults (max_results = max_results )
4041 res = research .run (query )
4142
4243 links = re .findall (r'https?://[^\s,\]]+' , res )
4344
4445 return links
46+ elif search_engine .lower () == "yahoo" :
47+ list_result = yahoo_search (query )
48+ results = []
49+ for page in list_result .pages :
50+ if len (results ) >= max_results : # Check if max_results has already been reached
51+ break # Exit loop if max_results has been reached
52+ try :
53+ results .append (page .link )
54+ except AttributeError :
55+ continue
56+ return results
4557 raise ValueError (
46- "The only search engines avaiable are DuckDuckGo or Google" )
58+ "The only search engines available are DuckDuckGo or Google" )
0 commit comments