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 fetchNodeFix
Marco Vinciguerra99adc9799f6c
diff --cc CHANGELOG.mdindex 03ea0c69,60e964c4..dffb9062--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -1,44 -1,35 +1,35 @@@- ## [0.10.0](https://github.com/VinciGit00/Scrapegraph-ai/compare/v0.9.0...v0.10.0) (2024-05-08)-## [0.10.0-beta.6](https://github.com/VinciGit00/Scrapegraph-ai/compare/v0.10.0-beta.5...v0.10.0-beta.6) (2024-05-09)-+ ### Bug Fixes- ### Features+ * add json integration ([0ab31c3](https://github.com/VinciGit00/Scrapegraph-ai/commit/0ab31c3fdbd56652ed306e60109301f60e8042d3))++ ## [0.10.0-beta.5](https://github.com/VinciGit00/Scrapegraph-ai/compare/v0.10.0-beta.4...v0.10.0-beta.5) (2024-05-09)- * add claude documentation ([5bdee55](https://github.com/VinciGit00/Scrapegraph-ai/commit/5bdee558760521bab818efc6725739e2a0f55d20))- * add gemini embeddings ([79daa4c](https://github.com/VinciGit00/Scrapegraph-ai/commit/79daa4c112e076e9c5f7cd70bbbc6f5e4930832c))- * add llava integration ([019b722](https://github.com/VinciGit00/Scrapegraph-ai/commit/019b7223dc969c87c3c36b6a42a19b4423b5d2af))- * add new hugging_face models ([d5547a4](https://github.com/VinciGit00/Scrapegraph-ai/commit/d5547a450ccd8908f1cf73707142b3481fbc6baa))- * Fix bug for gemini case when embeddings config not passed ([726de28](https://github.com/VinciGit00/Scrapegraph-ai/commit/726de288982700dab8ab9f22af8e26f01c6198a7))- * fixed custom_graphs example and robots_node ([84fcb44](https://github.com/VinciGit00/Scrapegraph-ai/commit/84fcb44aaa36e84f775884138d04f4a60bb389be))- * multiple graph instances ([dbb614a](https://github.com/VinciGit00/Scrapegraph-ai/commit/dbb614a8dd88d7667fe3daaf0263f5d6e9be1683))- * **node:** multiple url search in SearchGraph + fixes ([930adb3](https://github.com/VinciGit00/Scrapegraph-ai/commit/930adb38f2154ba225342466bfd1846c47df72a0))- * refactoring search function ([aeb1acb](https://github.com/VinciGit00/Scrapegraph-ai/commit/aeb1acbf05e63316c91672c99d88f8a6f338147f))+### Bug Fixes- * bug on .toml ([f7d66f5](https://github.com/VinciGit00/Scrapegraph-ai/commit/f7d66f51818dbdfddd0fa326f26265a3ab686b20))- * **llm:** fixed gemini api_key ([fd01b73](https://github.com/VinciGit00/Scrapegraph-ai/commit/fd01b73b71b515206cfdf51c1d52136293494389))- * **examples:** local, mixed models and fixed SearchGraph embeddings problem ([6b71ec1](https://github.com/VinciGit00/Scrapegraph-ai/commit/6b71ec1d2be953220b6767bc429f4cf6529803fd))- * **examples:** openai std examples ([186c0d0](https://github.com/VinciGit00/Scrapegraph-ai/commit/186c0d035d1d211aff33c38c449f2263d9716a07))- * removed .lock file for deployment ([d4c7d4e](https://github.com/VinciGit00/Scrapegraph-ai/commit/d4c7d4e7fcc2110beadcb2fc91efc657ec6a485c))+++ * fixed bugs for csv and xml ([324e977](https://github.com/VinciGit00/Scrapegraph-ai/commit/324e977b853ecaa55bac4bf86e7cd927f7f43d0d))++ ## [0.10.0-beta.4](https://github.com/VinciGit00/Scrapegraph-ai/compare/v0.10.0-beta.3...v0.10.0-beta.4) (2024-05-09)+++ ### Features++ * Add support for passing pdf path as source ([f10f3b1](https://github.com/VinciGit00/Scrapegraph-ai/commit/f10f3b1438e0c625b7f2fa52faeb5a6c12116113))- ### Docs+ ### Bug Fixes++ * limit python version to < 3.12 ([a37fbbc](https://github.com/VinciGit00/Scrapegraph-ai/commit/a37fbbcbcfc3ddd0cc66f586f279676b52c4abfe))- * update README.md ([17ec992](https://github.com/VinciGit00/Scrapegraph-ai/commit/17ec992b498839e001277e7bc3f0ebea49fbd00d))+ ## [0.10.0-beta.3](https://github.com/VinciGit00/Scrapegraph-ai/compare/v0.10.0-beta.2...v0.10.0-beta.3) (2024-05-09)- ### CI+ ### Features- * **release:** 0.10.0-beta.1 [skip ci] ([c47a505](https://github.com/VinciGit00/Scrapegraph-ai/commit/c47a505750ee63e0220b339478953155ef1f1771))- * **release:** 0.10.0-beta.2 [skip ci] ([3f0e069](https://github.com/VinciGit00/Scrapegraph-ai/commit/3f0e0694f3b08463f025586777f7c0594b5ecb14))- * **release:** 0.9.0-beta.2 [skip ci] ([5aa600c](https://github.com/VinciGit00/Scrapegraph-ai/commit/5aa600cb0a85d320ad8dc786af26ffa46dd4d097))- * **release:** 0.9.0-beta.3 [skip ci] ([da8c72c](https://github.com/VinciGit00/Scrapegraph-ai/commit/da8c72ce138bcfe2627924d25a67afcd22cfafd5))- * **release:** 0.9.0-beta.4 [skip ci] ([8c5397f](https://github.com/VinciGit00/Scrapegraph-ai/commit/8c5397f67a9f05e0c00f631dd297b5527263a888))- * **release:** 0.9.0-beta.5 [skip ci] ([532adb6](https://github.com/VinciGit00/Scrapegraph-ai/commit/532adb639d58640bc89e8b162903b2ed97be9853))- * **release:** 0.9.0-beta.6 [skip ci] ([8c0b46e](https://github.com/VinciGit00/Scrapegraph-ai/commit/8c0b46eb40b446b270c665c11b2c6508f4d5f4be))- * **release:** 0.9.0-beta.7 [skip ci] ([6911e21](https://github.com/VinciGit00/Scrapegraph-ai/commit/6911e21584767460c59c5a563c3fd010857cbb67))- * **release:** 0.9.0-beta.8 [skip ci] ([739aaa3](https://github.com/VinciGit00/Scrapegraph-ai/commit/739aaa33c39c12e7ab7df8a0656cad140b35c9db))+ * update info ([4ed0fb8](https://github.com/VinciGit00/Scrapegraph-ai/commit/4ed0fb89c3e6068190a7775bedcb6ae65ba59d18))## [0.10.0-beta.2](https://github.com/VinciGit00/Scrapegraph-ai/compare/v0.10.0-beta.1...v0.10.0-beta.2) (2024-05-08)diff --cc scrapegraphai/nodes/fetch_node.pyindex 2667f0be,52266b42..eeb2d0b4--- a/scrapegraphai/nodes/fetch_node.py+++ b/scrapegraphai/nodes/fetch_node.py@@@ -5,10 -6,9 +6,11 @@@ import jsofrom typing import List, Optionalfrom langchain_community.document_loaders import AsyncChromiumLoaderfrom langchain_core.documents import Document+ from langchain_community.document_loaders import PyPDFLoaderfrom .base_node import BaseNode-from ..utils.remover import remover+from ..utils.cleanup_html import cleanup_html+import requests+from bs4 import BeautifulSoupclass FetchNode(BaseNode):@@@ -31,12 -31,13 +33,14 @@@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.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.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)def execute(self, state):"""@@@ -69,26 -69,38 +72,50 @@@"source": "local_dir"})]# if it is a local directory++ # handling for pdf+ elif self.input == "pdf":+ loader = PyPDFLoader(source)+ compressed_document = loader.load()++ elif self.input == "csv":+ compressed_document = [Document(page_content=str(pd.read_csv(source)), metadata={+ "source": "csv"+ })]+ elif self.input == "json":+ f = open(source)+ compressed_document = [Document(page_content=str(json.load(f)), metadata={+ "source": "json"+ })]+ elif self.input == "xml":+ with open(source, 'r', encoding='utf-8') as f:+ data = f.read()+ compressed_document = [Document(page_content=data, metadata={+ "source": "xml"+ })]+ elif self.input == "pdf_dir":+ pass+elif not source.startswith("http"):- compressed_document = [Document(page_content=remover(source), metadata={+ compressed_document = [Document(page_content=cleanup_html(source), metadata={"source": "local_dir"})]+ elif self.useSoup:+ response = requests.get(source)+ if response.status_code == 200:+ soup = BeautifulSoup(response.text, 'html.parser')+ links = soup.find_all('a')+ link_urls = []+ for link in links:+ if 'href' in link.attrs:+ link_urls.append(link['href'])+ compressed_document = [Document(page_content=cleanup_html(soup.prettify(), link_urls))]+ 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 = AsyncChromiumLoader([source],proxies={"http": self.node_config["endpoint"]},