Python scraper based on AI
Python ai-crawlerai-scrapingai-searchcrawlerdata-extractionfirecrawl-alternativelarge-language-modelllmmarkdownragscrapingscraping-pythonweb-crawlerweb-crawlersweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
new function for searching
VinciGit00fff1f9ee5182
diff --git a/scrapegraphai/utils/research_web.py b/scrapegraphai/utils/research_web.pyindex d404f5c7..a4bce5f5 100644--- a/scrapegraphai/utils/research_web.py+++ b/scrapegraphai/utils/research_web.py@@ -1,31 +1,21 @@"""Module for making the request on the web"""-import requests+import re+from langchain_community.tools import DuckDuckGoSearchResults-def search_word_on_google(word):+def search_word_on_google(word, max_results=10):"""Function that given a word it finds it on the intenet+ Args:+ word (str): word to search on internet+ max_results (int): maximum number of results"""- url = f"https://www.google.com/search?q={word}"- headers = {- 'User-Agent': """ Mozilla/5.0 (Windows NT 10.0; Win64; x64) A- ppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"""- }- try:- response = requests.get(url, headers=headers, timeout=10)- response.raise_for_status() # Raise an exception for 4xx or 5xx status codes- except requests.RequestException as e:- print(f"Error occurred: {e}")- return+ search = DuckDuckGoSearchResults(max_results=max_results)+ res = search.run(word)- if response.status_code == 200:- print("Search request successful!")- # You can parse the HTML response using BeautifulSoup or other libraries- print("Response content:")- print(response.text)- else:- print(- f"Failed to make search request. Status code: {response.status_code}")+ links = re.findall(r'https?://\S+', res)++ return links