Skip to content

Python scraper based on AI

fixed documentation and fetch_text_node

VinciGit00ab71a6bc5ab7
diff --git a/examples/graph_examples/graph_from_text_example.py b/examples/graph_examples/graph_from_text_example.py
index 80563bd7..2c7027bf 100644
--- a/examples/graph_examples/graph_from_text_example.py
+++ b/examples/graph_examples/graph_from_text_example.py
@@ -6,7 +6,7 @@ import os
from dotenv import load_dotenv
from scrapegraphai.models import OpenAI
from scrapegraphai.graphs import BaseGraph
-from scrapegraphai.nodes import TextNode, ParseTextNode, GenerateAnswerNode
+from scrapegraphai.nodes import FetchTextNode, ParseTextNode, GenerateAnswerNode
load_dotenv()
@@ -25,7 +25,7 @@ with open("text_example.txt", "r", encoding="utf-8") as file:
# define the nodes for the graph
-fetch_html_node = TextNode("load_html")
+fetch_html_node = FetchTextNode("load_html")
parse_document_node = ParseTextNode("parse_document")
generate_answer_node = GenerateAnswerNode(model, "generate_answer")
@@ -45,7 +45,7 @@ graph = BaseGraph(
# execute the graph
inputs = {"user_input": "Give me the name of all the news",
- "url": text}
+ "text": text}
result = graph.execute(inputs)
# get the answer from the result
diff --git a/scrapegraphai/nodes/__init__.py b/scrapegraphai/nodes/__init__.py
index 36fb58a9..86f7e841 100644
--- a/scrapegraphai/nodes/__init__.py
+++ b/scrapegraphai/nodes/__init__.py
@@ -9,5 +9,5 @@ from .parse_html_node import ParseHTMLNode
from .rag_node import RAGNode
from .text_to_speech_node import TextToSpeechNode
from .image_to_text_node import ImageToTextNode
-from .text_node import TextNode
+from .fetch_text_node import FetchTextNode
from .parse_text_node import ParseTextNode
diff --git a/scrapegraphai/nodes/text_node.py b/scrapegraphai/nodes/fetch_text_node.py
similarity index 88%
rename from scrapegraphai/nodes/text_node.py
rename to scrapegraphai/nodes/fetch_text_node.py
index fb6ee5c6..b13c35bb 100644
--- a/scrapegraphai/nodes/text_node.py
+++ b/scrapegraphai/nodes/fetch_text_node.py
@@ -1,10 +1,10 @@
""" 
-Module for TextNode
+Module for FetchTextNode
"""
from .base_node import BaseNode
-class TextNode(BaseNode):
+class FetchTextNode(BaseNode):
"""
A node for loading raw text into the state.
@@ -27,7 +27,7 @@ class TextNode(BaseNode):
def __init__(self, node_name: str):
"""
- Initializes the TextNode with a node name.
+ Initializes the FetchTextNode with a node name.
Args:
node_name (str): The unique name for the node.
@@ -39,7 +39,7 @@ class TextNode(BaseNode):
Loads raw text content into the state.
Args:
- state (dict): The current state, expected to contain a 'url' key
+ state (dict): The current state, expected to contain a 'text' key
indicating the source of the text.
Returns:
@@ -50,8 +50,8 @@ class TextNode(BaseNode):
"""
print("---LOADING TEXT CODE---")
- if 'url' not in state:
+ if 'text' not in state:
raise KeyError("The 'url' key is required to load the text.")
- state["document"] = state["url"]
+ state["document"] = state["text"]
return state
diff --git a/scrapegraphai/nodes/parse_text_node.py b/scrapegraphai/nodes/parse_text_node.py
index b94e5287..ee784b29 100644
--- a/scrapegraphai/nodes/parse_text_node.py
+++ b/scrapegraphai/nodes/parse_text_node.py
@@ -42,14 +42,15 @@ class ParseTextNode(BaseNode):
Args:
state (dict): Expects the following keys:
- * 'document': The HTML content to parse.
- * 'tags' (optional): A list of HTML tags to target for extraction.
+ 'document': The HTML content to parse.
+ 'tags' (optional): A list of HTML tags to target for extraction.
Returns:
dict: Updated state with the following:
- * 'parsed_document': The extracted content
+ 'parsed_document': The extracted content
(or the original document if no tags were provided).
- * 'document_chunks': The original document split into chunks (using RecursiveCharacterTextSplitter)
+ 'document_chunks': The original document split into chunka
+ (using RecursiveCharacterTextSplitter)
for larger documents.
Raises: