Python scraper based on AI
Python ai-crawlerai-scrapingai-searchcrawlerdata-extractionfirecrawl-alternativelarge-language-modelllmmarkdownragscrapingscraping-pythonweb-crawlerweb-crawlersweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
refactor examples
EURAC\marperini57a53bd6af9d
diff --git a/examples/graph_examples/custom_graph_openai.py b/examples/graph_examples/custom_graph_openai.pyindex 4f982ace..48fbc9d6 100644--- a/examples/graph_examples/custom_graph_openai.py+++ b/examples/graph_examples/custom_graph_openai.py@@ -7,7 +7,6 @@ from dotenv import load_dotenvfrom scrapegraphai.models import OpenAIfrom scrapegraphai.graphs import BaseGraphfrom scrapegraphai.nodes import FetchNode, ParseNode, RAGNode, GenerateAnswerNode-from scrapegraphai.utils import convert_to_csv, convert_to_jsonload_dotenv()openai_key = os.getenv("OPENAI_APIKEY")@@ -68,8 +67,4 @@ result = graph.execute({# get the answer from the resultresult = result.get("answer", "No answer found.")-print(result)--# Save to json and csv-convert_to_csv(result, "result")-convert_to_json(result, "result")+print(result)\ No newline at end of filediff --git a/examples/graph_examples/smart_scraper_example.py b/examples/graph_examples/smart_scraper_example.pyindex cc9ba530..a8bc2d92 100644--- a/examples/graph_examples/smart_scraper_example.py+++ b/examples/graph_examples/smart_scraper_example.py@@ -5,7 +5,6 @@ Basic example of scraping pipeline using SmartScraperimport osfrom dotenv import load_dotenvfrom scrapegraphai.graphs import SmartScraperGraph-from scrapegraphai.utils import convert_to_csv, convert_to_jsonload_dotenv()openai_key = os.getenv("OPENAI_APIKEY")@@ -28,7 +27,3 @@ smart_scraper_graph = SmartScraperGraph(result = smart_scraper_graph.run()print(result)--# Save to json and csv-convert_to_csv(result, "result")-convert_to_json(result, "result")diff --git a/examples/graph_examples/speech_graph_example.py b/examples/graph_examples/speech_graph_example.pyindex 6c2d9785..7afac269 100644--- a/examples/graph_examples/speech_graph_example.py+++ b/examples/graph_examples/speech_graph_example.py@@ -5,7 +5,6 @@ Basic example of scraping pipeline using SpeechSummaryGraphimport osfrom dotenv import load_dotenvfrom scrapegraphai.graphs import SpeechGraph-from scrapegraphai.utils import convert_to_csv, convert_to_jsonload_dotenv()openai_key = os.getenv("OPENAI_APIKEY")@@ -37,7 +36,3 @@ speech_graph = SpeechGraph(result = speech_graph.run()print(result.get("answer", "No answer found"))--# Save to json and csv-convert_to_csv(result, "result")-convert_to_json(result, "result")diff --git a/scrapegraphai/nodes/search_internet_node.py b/scrapegraphai/nodes/search_internet_node.pyindex 021729f9..0b33f79b 100644--- a/scrapegraphai/nodes/search_internet_node.py+++ b/scrapegraphai/nodes/search_internet_node.py@@ -95,7 +95,7 @@ class SearchInternetNode(BaseNode):print(f"Search Query: {search_query}")# TODO: handle multiple URLs- answer = search_on_web(query=search_query, web_browser="Google", max_results=1)[0]+ answer = search_on_web(query=search_query, search_engine="DuckDuckGo", max_results=1)[0]# Update the state with the generated answerstate.update({self.output[0]: answer})diff --git a/scrapegraphai/utils/research_web.py b/scrapegraphai/utils/research_web.pyindex 373b3168..8f48adcd 100644--- a/scrapegraphai/utils/research_web.py+++ b/scrapegraphai/utils/research_web.py@@ -7,12 +7,12 @@ from langchain_community.tools import DuckDuckGoSearchResultsfrom googlesearch import search-def search_on_web(query: str, web_browser: str = "Google", max_results: int = 10) -> List[str]:+def search_on_web(query: str, search_engine: str = "Google", max_results: int = 10) -> List[str]:"""Function that given a query it finds it on the intenetArgs:query (str): query to search on internet- web_browser (str, optional): type of browser, it could be DuckDuckGo or Google,+ search_engine (str, optional): type of browser, it could be DuckDuckGo or Google,default: Googlemax_results (int, optional): maximum number of results@@ -20,18 +20,18 @@ def search_on_web(query: str, web_browser: str = "Google", max_results: int = 10List[str]: List of strings of web link"""- if web_browser == "Google":+ if search_engine == "Google":res = []for url in search(query, stop=max_results):res.append(url)return res- elif web_browser == "DuckDuckGo":+ elif search_engine == "DuckDuckGo":research = DuckDuckGoSearchResults(max_results=max_results)res = research.run(query)- links = re.findall(r'https?://\S+', res)+ links = re.findall(r'https?://[^\s,\]]+', res)return linksraise ValueError(- "The only web browsers avaiable are DuckDuckGo or Google")+ "The only search engines avaiable are DuckDuckGo or Google")