MCPcopy Index your code
hub / github.com/ScrapeGraphAI/Scrapegraph-ai / ParseNode

Class ParseNode

scrapegraphai/nodes/parse_node.py:17–219  ·  view source on GitHub ↗

A node responsible for parsing HTML content from a document. The parsed content is split into chunks for further processing. This node enhances the scraping workflow by allowing for targeted extraction of content, thereby optimizing the processing of large HTML documents. Attr

Source from the content-addressed store, hash-verified

15
16
17class ParseNode(BaseNode):
18 """
19 A node responsible for parsing HTML content from a document.
20 The parsed content is split into chunks for further processing.
21
22 This node enhances the scraping workflow by allowing for targeted extraction of
23 content, thereby optimizing the processing of large HTML documents.
24
25 Attributes:
26 verbose (bool): A flag indicating whether to show print statements during execution.
27
28 Args:
29 input (str): Boolean expression defining the input keys needed from the state.
30 output (List[str]): List of output keys to be updated in the state.
31 node_config (dict): Additional configuration for the node.
32 node_name (str): The unique identifier name for the node, defaulting to "Parse".
33 """
34
35 url_pattern = re.compile(
36 r"[http[s]?:\/\/]?(www\.)?([-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b[-a-zA-Z0-9()@:%_\+.~#?&\/\/=]*)"
37 )
38 relative_url_pattern = re.compile(r"[\(](/[^\(\)\s]*)")
39
40 def __init__(
41 self,
42 input: str,
43 output: List[str],
44 node_config: Optional[dict] = None,
45 node_name: str = "ParseNode",
46 ):
47 super().__init__(node_name, "node", input, output, 1, node_config)
48
49 self.verbose = (
50 False if node_config is None else node_config.get("verbose", False)
51 )
52 self.parse_html = (
53 True if node_config is None else node_config.get("parse_html", True)
54 )
55 self.parse_urls = (
56 False if node_config is None else node_config.get("parse_urls", False)
57 )
58
59 self.llm_model = node_config.get("llm_model")
60 self.chunk_size = node_config.get("chunk_size")
61
62 def execute(self, state: dict) -> dict:
63 """
64 Executes the node's logic to parse the HTML document content and split it into chunks.
65
66 Args:
67 state (dict): The current state of the graph. The input keys will be used to fetch the
68 correct data from the state.
69
70 Returns:
71 dict: The updated state with the output key containing the parsed content chunks.
72
73 Raises:
74 KeyError: If the input keys are not found in the state, indicating that the

Callers 11

_create_graphMethod · 0.90
_create_graphMethod · 0.85
_create_graphMethod · 0.85
_create_graphMethod · 0.85
_create_graphMethod · 0.85
_create_graphMethod · 0.85
_create_graphMethod · 0.85
_create_graphMethod · 0.85
_create_graphMethod · 0.85

Calls

no outgoing calls

Tested by 1

_create_graphMethod · 0.72