Python scraper based on AI
Python ai-crawlerai-scrapingai-searchcrawlerdata-extractionfirecrawl-alternativelarge-language-modelllmmarkdownragscrapingscraping-pythonweb-crawlerweb-crawlersweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
refactoring of research function
VinciGit00672e9a5191f6
diff --git a/scrapegraphai/utils/research_web.py b/scrapegraphai/utils/research_web.pyindex 35e71b54..d404f5c7 100644--- a/scrapegraphai/utils/research_web.py+++ b/scrapegraphai/utils/research_web.py@@ -10,11 +10,16 @@ def search_word_on_google(word):"""url = f"https://www.google.com/search?q={word}"headers = {- 'User-Agent': """Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (- KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"""+ '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"""}- response = requests.get(url, headers=headers)+ 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}")+ returnif response.status_code == 200:print("Search request successful!")@@ -24,5 +29,3 @@ def search_word_on_google(word):else:print(f"Failed to make search request. Status code: {response.status_code}")--# Example usage