Python scraper based on AI
Python ai-crawlerai-scrapingai-searchcrawlerdata-extractionfirecrawl-alternativelarge-language-modelllmmarkdownragscrapingscraping-pythonweb-crawlerweb-crawlersweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
add trigger
Marco Vinciguerra7af411aa99ab
diff --git a/scrapegraphai/graphs/script_creator_graph.py b/scrapegraphai/graphs/script_creator_graph.pyindex 83bef2ab..b10c2baa 100644--- a/scrapegraphai/graphs/script_creator_graph.py+++ b/scrapegraphai/graphs/script_creator_graph.py@@ -64,7 +64,7 @@ class ScriptCreatorGraph(AbstractGraph):"""fetch_node = FetchNode(- input="url | local_dir",+ input="url_for_script | local_dir",output=["doc", "link_urls", "img_urls"],)parse_node = ParseNode(diff --git a/scrapegraphai/graphs/smart_scraper_graph.py b/scrapegraphai/graphs/smart_scraper_graph.pyindex cfbfc000..af6dbcea 100644--- a/scrapegraphai/graphs/smart_scraper_graph.py+++ b/scrapegraphai/graphs/smart_scraper_graph.py@@ -62,9 +62,10 @@ class SmartScraperGraph(AbstractGraph):BaseGraph: A graph instance representing the web scraping workflow."""fetch_node = FetchNode(- input="url | local_dir",+ input="url_for_scraping | local_dir",output=["doc", "link_urls", "img_urls"],node_config={+ "llm_model": self.llm_model,"loader_kwargs": self.config.get("loader_kwargs", {}),})diff --git a/scrapegraphai/nodes/fetch_node.py b/scrapegraphai/nodes/fetch_node.pyindex f38cdfb9..e33d1c9a 100644--- a/scrapegraphai/nodes/fetch_node.py+++ b/scrapegraphai/nodes/fetch_node.py@@ -14,6 +14,7 @@ from ..docloaders import ChromiumLoaderfrom ..utils.convert_to_md import convert_to_mdfrom ..utils.logging import get_loggerfrom .base_node import BaseNode+from ..models import OpenAIclass FetchNode(BaseNode):@@ -57,6 +58,12 @@ class FetchNode(BaseNode):self.loader_kwargs = ({} if node_config is None else node_config.get("loader_kwargs", {}))+ self.llm_model = (+ {} if node_config is None else node_config.get("llm_model", {})+ )+ self.force = (+ {} if node_config is None else node_config.get("force", {})+ )def execute(self, state):"""@@ -136,7 +143,12 @@ class FetchNode(BaseNode):self.logger.info(f"--- (Fetching HTML from: {source}) ---")if not source.strip():raise ValueError("No HTML body content found in the local source.")- parsed_content = convert_to_md(source)++ parsed_content = source++ if isinstance(self.llm_model, OpenAI) and self.input == "-----" or self.force:+ parsed_content = convert_to_md(source)+compressed_document = [Document(page_content=parsed_content, metadata={"source": "local_dir"})]@@ -147,7 +159,11 @@ 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 = convert_to_md(source)++ parsed_content = source++ if isinstance(self.llm_model, OpenAI) and self.input == "-----" or self.force:+ parsed_content = convert_to_md(source)compressed_document = [Document(page_content=parsed_content)]else:self.logger.warning(@@ -166,8 +182,10 @@ class FetchNode(BaseNode):if not document or not document[0].page_content.strip():raise ValueError("No HTML body content found in the document fetched by ChromiumLoader.")+ parsed_content = document[0].page_content- parsed_content = convert_to_md(document[0].page_content)+ if isinstance(self.llm_model, OpenAI) and self.input == "-----" or self.force:+ parsed_content = convert_to_md(document[0].page_content)compressed_document = [Document(page_content=parsed_content, metadata={"source": "html file"})diff --git a/scrapegraphai/nodes/generate_answer_node.py b/scrapegraphai/nodes/generate_answer_node.pyindex 029f0a44..dddc9f60 100644--- a/scrapegraphai/nodes/generate_answer_node.py+++ b/scrapegraphai/nodes/generate_answer_node.py@@ -101,7 +101,7 @@ class GenerateAnswerNode(BaseNode):"format_instructions": format_instructions})chain = prompt | self.llm_model | output_parseranswer = chain.invoke({"question": user_prompt})-+else:prompt = PromptTemplate(template=template_chunks,diff --git a/scrapegraphai/utils/convert_to_md.py b/scrapegraphai/utils/convert_to_md.pyindex 977ec581..609643bf 100644--- a/scrapegraphai/utils/convert_to_md.py+++ b/scrapegraphai/utils/convert_to_md.py@@ -4,10 +4,9 @@ convert_to_md modulimport html2textimport mdformatfrom trafilatura import extract-from markdownify import markdownify-import pyhtml2md-def convert_to_md(html, provider="local"):++def convert_to_md(html):""" Convert HTML to Markdown.This function uses the html2text library to convert the provided HTML content to Markdownformat.@@ -22,12 +21,6 @@ def convert_to_md(html, provider="local"):'This is a paragraph.\n\n# This is a heading.'Note: All the styles and links are ignored during the conversion. """- if provider == "openai":- converter = html2text.HTML2Text()- formatted = converter.handle(html)- a = mdformat.text(formatted)- else:- a = extract(filecontent=html,include_images=True, include_links=True, include_tables=True, output_format="markdown")- b = markdownify(html, keep_inline_images_in=['td', 'th', 'a', 'figure'],)- c = pyhtml2md.convert(html)- return a++ return extract(filecontent=html,include_images=True,+ include_links=True, include_tables=True, output_format="markdown")