Python scraper based on AI
Python ai-crawlerai-scrapingai-searchcrawlerdata-extractionfirecrawl-alternativelarge-language-modelllmmarkdownragscrapingscraping-pythonweb-crawlerweb-crawlersweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
removed examples
VinciGit00389b52aabbdb
diff --git a/scrapegraphai/graphs/search_graph.py b/scrapegraphai/graphs/search_graph.pyindex 9c463e1a..8c75e443 100644--- a/scrapegraphai/graphs/search_graph.py+++ b/scrapegraphai/graphs/search_graph.py@@ -100,12 +100,11 @@ class SearchGraph(AbstractGraph):def run(self) -> str:"""Executes the web scraping and searching process.-+Returns:str: The answer to the prompt."""-inputs = {"user_prompt": self.prompt}self.final_state, self.execution_info = self.graph.execute(inputs)- return self.final_state.get("answer", "No answer found.")\ No newline at end of file+ return self.final_state.get("answer", "No answer found.")diff --git a/scrapegraphai/nodes/search_internet_node.py b/scrapegraphai/nodes/search_internet_node.pyindex 01095ef8..48722a46 100644--- a/scrapegraphai/nodes/search_internet_node.py+++ b/scrapegraphai/nodes/search_internet_node.py@@ -27,12 +27,14 @@ class SearchInternetNode(BaseNode):node_name (str): The unique identifier name for the node, defaulting to "SearchInternet"."""- def __init__(self, input: str, output: List[str], node_config: dict,+ def __init__(self, input: str, output: List[str], node_config: Optional[dict] = None,node_name: str = "SearchInternet"):super().__init__(node_name, "node", input, output, 1, node_config)self.llm_model = node_config["llm_model"]- self.verbose = True if node_config is None else node_config.get("verbose", False)+ self.verbose = True if node_config is None else node_config.get(+ "verbose", False)+ self.max_results = node_config.get("max_results", 3)def execute(self, state: dict) -> dict:"""@@ -84,9 +86,12 @@ class SearchInternetNode(BaseNode):if self.verbose:print(f"Search Query: {search_query}")-- # TODO: handle multiple URLs- answer = search_on_web(query=search_query, max_results=1)[0]+ answer = search_on_web(+ query=search_query, max_results=self.max_results)++ if len(answer) == 0:+ # raise an exception if no answer is found+ raise ValueError("Zero results found for the search query.")# Update the state with the generated answerstate.update({self.output[0]: answer})diff --git a/scrapegraphai/nodes/search_link_node.py b/scrapegraphai/nodes/search_link_node.pyindex 037b862e..cdbd9f67 100644--- a/scrapegraphai/nodes/search_link_node.py+++ b/scrapegraphai/nodes/search_link_node.py@@ -33,12 +33,13 @@ class SearchLinkNode(BaseNode):node_name (str): The unique identifier name for the node, defaulting to "GenerateAnswer"."""- def __init__(self, input: str, output: List[str], node_config: dict,+ def __init__(self, input: str, output: List[str], node_config: Optional[dict] = None,node_name: str = "GenerateLinks"):super().__init__(node_name, "node", input, output, 1, node_config)self.llm_model = node_config["llm_model"]- self.verbose = True if node_config is None else node_config.get("verbose", False)+ self.verbose = True if node_config is None else node_config.get(+ "verbose", False)def execute(self, state: dict) -> dict:"""@@ -73,10 +74,11 @@ class SearchLinkNode(BaseNode):links.append(soup.find_all("a"))state.update({self.output[0]: {elem for elem in links}})- except Exception as e:+ except Exception:if self.verbose:- print("Error extracting links using classical methods. Using LLM to extract links.")-+ print(+ "Error extracting links using classical methods. Using LLM to extract links.")+output_parser = JsonOutputParser()template_chunks = """