Python scraper based on AI
Python ai-crawlerai-scrapingai-searchcrawlerdata-extractionfirecrawl-alternativelarge-language-modelllmmarkdownragscrapingscraping-pythonweb-crawlerweb-crawlersweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
modify fetch node with no cut mode
Marco Vinciguerra9b45ebcdcf95
diff --git a/examples/extras/no_cut.py b/examples/extras/no_cut.pynew file mode 100644index 00000000..b7aa3452--- /dev/null+++ b/examples/extras/no_cut.py@@ -0,0 +1,43 @@+"""+This example shows how to do not process the html code in the fetch phase+"""++import os, json+from scrapegraphai.graphs import SmartScraperGraph+from scrapegraphai.utils import prettify_exec_info+++# ************************************************+# Define the configuration for the graph+# ************************************************+++graph_config = {+ "llm": {+ "api_key": "s",+ "model": "gpt-3.5-turbo",+ },+ "cut": False,+ "verbose": True,+ "headless": False,+}++# ************************************************+# Create the SmartScraperGraph instance and run it+# ************************************************++smart_scraper_graph = SmartScraperGraph(+ prompt="Extract me the python code inside the page",+ source="https://www.exploit-db.com/exploits/51447",+ config=graph_config+)++result = smart_scraper_graph.run()+print(json.dumps(result, indent=4))++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = smart_scraper_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))diff --git a/scrapegraphai/graphs/smart_scraper_graph.py b/scrapegraphai/graphs/smart_scraper_graph.pyindex 2b03533e..633e0569 100644--- a/scrapegraphai/graphs/smart_scraper_graph.py+++ b/scrapegraphai/graphs/smart_scraper_graph.py@@ -66,6 +66,8 @@ class SmartScraperGraph(AbstractGraph):output=["doc", "link_urls", "img_urls"],node_config={"llm_model": self.llm_model,+ "force": self.config.get("force", False),+ "cut": self.config.get("cut", True),"loader_kwargs": self.config.get("loader_kwargs", {}),})diff --git a/scrapegraphai/nodes/fetch_node.py b/scrapegraphai/nodes/fetch_node.pyindex 1951df39..36e36db5 100644--- a/scrapegraphai/nodes/fetch_node.py+++ b/scrapegraphai/nodes/fetch_node.py@@ -71,6 +71,10 @@ class FetchNode(BaseNode):False if node_config is None else node_config.get("script_creator", False))+ self.cut = (+ False if node_config is None else node_config.get("cut", True)+ )+def execute(self, state):"""Executes the node's logic to fetch HTML content from a specified URL and@@ -105,7 +109,7 @@ class FetchNode(BaseNode):compressed_document = [source]-+state.update({self.output[0]: compressed_document})return state# handling pdf@@ -165,10 +169,13 @@ class FetchNode(BaseNode):if response.status_code == 200:if not response.text.strip():raise ValueError("No HTML body content found in the response.")++ parsed_content = response++ if not self.cut:+ parsed_content = cleanup_html(response, source)- parsed_content = cleanup_html(response, source)-- if isinstance(self.llm_model, OpenAI) and not self.script_creator or self.force and not self.script_creator and not:+ if (isinstance(self.llm_model, OpenAI) and not self.script_creator) or (self.force and not self.script_creator):parsed_content = convert_to_md(source)compressed_document = [Document(page_content=parsed_content)]else: