Python scraper based on AI
Python ai-crawlerai-scrapingai-searchcrawlerdata-extractionfirecrawl-alternativelarge-language-modelllmmarkdownragscrapingscraping-pythonweb-crawlerweb-crawlersweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
Merge branch 'pre/beta' into fix/fetch-node-proxybroker
Marco Perini7e8acd8e6a15
diff --cc docs/source/introduction/overview.rstindex ffb0a5b3,43901011..1ed4167c--- a/docs/source/introduction/overview.rst+++ b/docs/source/introduction/overview.rst@@@ -17,9 -12,20 +17,19 @@@ providing a more flexible and low-maintWhy ScrapegraphAI?==================-ScrapegraphAI in our vision represents a significant step forward in the field of web scraping, offering an open-source solution designed to meet the needs of a constantly evolving web landscape. Here's why ScrapegraphAI stands out:--Flexibility and Adaptability-^^^^^^^^^^^^^^^^^^^^^^^^^^^-Traditional web scraping tools often rely on fixed patterns or manual configuration to extract data from web pages. ScrapegraphAI, leveraging the power of LLMs, adapts to changes in website structures, reducing the need for constant developer intervention.+Traditional web scraping tools often rely on fixed patterns or manual configuration to extract data from web pages.+ScrapegraphAI, leveraging the power of LLMs, adapts to changes in website structures, reducing the need for constant developer intervention.This flexibility ensures that scrapers remain functional even when website layouts change.+We support many Large Language Models (LLMs) including GPT, Gemini, Groq, Azure, Hugging Face etc.- as well as local models which can run on your machine using Ollama.++as well as local models which can run on your machine using Ollama.+-Overview-========++Diagram++=======+ With ScrapegraphAI you first construct a pipeline of steps you want to execute by combining nodes into a graph.+ Executing the graph takes care of all the steps that are often part of scraping: fetching, parsing etc...+ Finally the scraped and processed data gets fed to an LLM which generates a response.++ .. image:: ../../assets/project_overview_diagram.png+ :align: center- :alt: ScrapegraphAI Overview++ :alt: ScrapegraphAI Overviewdiff --cc scrapegraphai/nodes/fetch_node.pyindex baf48615,ea84b824..b770a2b3--- a/scrapegraphai/nodes/fetch_node.py+++ b/scrapegraphai/nodes/fetch_node.py@@@ -1,17 -1,15 +1,18 @@@"""FetchNode Module"""-import pandas as pd+import json+ import requestsfrom typing import List, Optional-from langchain_community.document_loaders import AsyncChromiumLoader-from langchain_core.documents import Document++import pandas as pdfrom langchain_community.document_loaders import PyPDFLoader+from langchain_core.documents import Document++from ..docloaders import ChromiumLoader- from ..utils.remover import removerfrom .base_node import BaseNode+ from ..utils.cleanup_html import cleanup_htmlclass FetchNode(BaseNode):@@@ -34,24 -32,15 +35,26 @@@node_name (str): The unique identifier name for the node, defaulting to "Fetch"."""- def __init__(self, input: str, output: List[str], node_config: Optional[dict] = None, node_name: str = "Fetch"):+ def __init__(+ self,+ input: str,+ output: List[str],+ node_config: Optional[dict] = None,+ node_name: str = "Fetch",+ ):super().__init__(node_name, "node", input, output, 1)- self.headless = True if node_config is None else node_config.get(- "headless", True)- self.verbose = False if node_config is None else node_config.get(- "verbose", False)- self.useSoup = True if node_config is None else node_config.get(- "useSoup", True)+ self.headless = (+ True if node_config is None else node_config.get("headless", True)+ )+ self.verbose = (+ False if node_config is None else node_config.get("verbose", False)+ )++ self.useSoup = (++ True if node_config is None else node_config.get("useSoup", True)+ self.loader_kwargs = (+ {} if node_config is None else node_config.get("loader_kwargs", {})+ )def execute(self, state):"""@@@ -114,22 -97,35 +117,30 @@@passelif not source.startswith("http"):- compressed_document = [- Document(page_content=remover(source), metadata={"source": "local_dir"})- ]- compressed_document = [Document(page_content=cleanup_html(source), metadata={- "source": "local_dir"- })]++ compressed_document = [Document(page_content=cleanup_html(source),++ metadata={"source": "local_dir"}++ )]++ elif self.useSoup:+ response = requests.get(source)+ if response.status_code == 200:+ cleanedup_html = cleanup_html(response.text, source)+ compressed_document = [Document(page_content=cleanedup_html)]+ else:+ print(f"Failed to retrieve contents from the webpage at url: {url}")else:- if self.node_config is not None and self.node_config.get("endpoint") is not None:+ loader_kwargs = {}- loader = AsyncChromiumLoader(- [source],- proxies={"http": self.node_config["endpoint"]},- headless=self.headless,- )- else:- loader = AsyncChromiumLoader(- [source],- headless=self.headless,- )+ if self.node_config is not None:+ loader_kwargs = self.node_config.get("loader_kwargs", {})++ loader = ChromiumLoader([source], headless=self.headless, **loader_kwargs)document = loader.load()compressed_document = [- Document(page_content=remover(str(document[0].page_content)))- Document(page_content=cleanup_html(str(document[0].page_content)))]++ Document(page_content=cleanup_html(str(document[0].page_content)))+ ]state.update({self.output[0]: compressed_document})return statediff --cc scrapegraphai/utils/__init__.pyindex dde9971d,8662cc5c..72a8b96c--- a/scrapegraphai/utils/__init__.py+++ b/scrapegraphai/utils/__init__.py@@@ -5,7 -5,5 +5,7 @@@from .convert_to_csv import convert_to_csvfrom .convert_to_json import convert_to_jsonfrom .prettify_exec_info import prettify_exec_info-from .proxy_rotation import proxy_generator+from .proxy_rotation import Proxy, parse_or_search_proxy, search_proxy_servers- from .remover import remover+from .save_audio_from_bytes import save_audio_from_bytes+from .sys_dynamic_import import dynamic_import, srcfile_import+ from .cleanup_html import cleanup_html