Skip to content

Python scraper based on AI

fix: add json integration

VinciGit000ab31c3fdbd5
diff --git a/scrapegraphai/graphs/json_scraper_graph.py b/scrapegraphai/graphs/json_scraper_graph.py
index aec41195..dc341eae 100644
--- a/scrapegraphai/graphs/json_scraper_graph.py
+++ b/scrapegraphai/graphs/json_scraper_graph.py
@@ -54,7 +54,7 @@ class JSONScraperGraph(AbstractGraph):
"""
fetch_node = FetchNode(
- input="json_dir",
+ input="json",
output=["doc"],
)
parse_node = ParseNode(
@@ -106,4 +106,4 @@ class JSONScraperGraph(AbstractGraph):
inputs = {"user_prompt": self.prompt, self.input_key: self.source}
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/fetch_node.py b/scrapegraphai/nodes/fetch_node.py
index dfaf8bb6..52266b42 100644
--- a/scrapegraphai/nodes/fetch_node.py
+++ b/scrapegraphai/nodes/fetch_node.py
@@ -2,6 +2,7 @@
FetchNode Module
"""
import pandas as pd
+import json
from typing import List, Optional
from langchain_community.document_loaders import AsyncChromiumLoader
from langchain_core.documents import Document
@@ -75,8 +76,13 @@ class FetchNode(BaseNode):
compressed_document = loader.load()
elif self.input == "csv":
- compressed_document = [Document(page_content=pd.read_csv(source), metadata={
- "source": "xml"
+ 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: