Field extraction path generation method based on webpage structure analysis
By using node fragmentation, nested hierarchical indexing, and same-level adjacency indexing, the webpage field extraction path is automatically determined, solving the problems of unstable paths and high maintenance costs in existing technologies, and achieving stable field extraction under non-standard tags and repetitive structures.
Patent Information
- Application Number
- CN202611700275.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-10-30
- Publication Date
- 2026-11-27
AI Technical Summary
Existing methods for extracting web page fields and generating paths rely on a complete document object model tree and manually configured positioning expressions. These methods cannot effectively handle non-standard tags and repetitive structures, resulting in unstable paths and high maintenance costs.
By segmenting node fragments, establishing nested hierarchical indexes and adjacent indexes at the same level, generating candidate field paths, replaying hits, and folding conflicts, the field extraction path is automatically determined from the original webpage source code, reducing the reliance on complete parse trees and manual rules.
Maintain the stability of field extraction paths under non-standard webpage structures and repetitive structures, reduce the mixing of irrelevant content and field omissions, and lower maintenance costs.
Smart Images

Figure CN123178741A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of web page data extraction technology, specifically to a method for generating field extraction paths based on web page structure analysis. Background Technology
[0002] Generating field extraction paths for web pages typically relies on the Document Object Model (DOM) tree and manually configured positioning expressions such as XPath and CSS selectors. Existing techniques involve parsing the web page source code to construct a complete tree structure, then specifying node paths using fixed rules or template tools to extract the target field from the corresponding node. For web pages with well-defined tag closures and a fixed structure, this method can generate field extraction paths corresponding to the template.
[0003] In actual webpage source code, there are numerous instances of unclosed tags, misordered tags, embedded comments, script fragments, and style fragments. Browser errors in correcting non-standard tags and merging nodes during parsing can lead to discrepancies between the parse tree structure and the original source code. The field extraction paths generated from this parse tree may shift during partial page structure adjustments or tag anomalies, resulting in inaccurate node hits or extraction failures.
[0004] In repetitive structural areas such as lists and forms, combinations of similar nodes can form multiple candidate paths. Fixed rules struggle to automatically determine the coverage relationship and effective scope between candidate paths, leading to potential conflicts. Some paths may only cover a single field or a partial segment, while others may cover multiple fields, resulting in irrelevant content or omission of target fields in the extraction results. The selection and confirmation of candidate paths typically rely on manual comparison, resulting in high maintenance costs.
[0005] In situations where incomplete tag closures, ambiguous node boundaries, and repetitive structures coexist, it is necessary to obtain available node hierarchy and adjacency relationships from the original webpage source code, and determine the field extraction path that is consistent with the coverage of the target field from multiple candidate field paths. Summary of the Invention
[0006] To address the problems of existing methods for generating field extraction paths for web pages, which rely on complete Document Object Model (DOM) trees and manually configured location expressions, resulting in unstable paths and high maintenance costs under non-standard tag structures and repetitive structures, this invention provides a field extraction path generation method based on web page structure analysis. This method automatically determines field extraction paths from the original web page source code through node fragment segmentation, nested hierarchical indexing and same-level adjacency indexing, candidate field path generation, hit replay, and conflict folding. This reduces reliance on complete parse trees and manual rules, ensuring the stability of field extraction paths under non-standard and repetitive web page structures.
[0007] To achieve the above objectives, the present invention provides the following technical solution: a method for generating field extraction paths based on webpage structure analysis, comprising: Obtain the source code of the target webpage, and segment the source code of the target webpage according to the start and end positions of tags and the boundaries of text nodes to obtain a sequence of node fragments; Based on the pairing relationship between open and closed labels in the node fragment sequence, nested hierarchical index and same-level adjacency index are established. The nested hierarchical index records the parent fragment identifier and level number, and the same-level adjacency index records the previous neighbor fragment identifier and the next neighbor fragment identifier. Based on nested hierarchical indexes and same-level adjacency indexes, candidate field paths are generated by combining repeated hierarchical jumps and adjacency fragments. Each candidate field path consists of node attribute tokens, hierarchical transfer tokens, and adjacent position tokens. The candidate field path is replayed in the node fragment sequence to record the hit nodes, hit continuous segments and text offsets, and obtain the set of hit nodes and path span records. Based on the coverage relationship between the hit node sets and the length of continuous segments in the path span record, conflict folding is performed on the candidate field path to determine the field extraction path.
[0008] Preferably, the step of segmenting the target webpage source code according to the start and end positions of tags and the boundaries of text nodes includes: Identify comment tags, script sections, and style sections in the source code of the target webpage, and mark comment tags, script sections, and style sections as invisible fragments; Establish segmentation points for each open tag start position, close tag end position, and continuous text character boundary outside of the invisible segment; The target webpage source code is divided into node fragments according to the split points. Each node fragment carries the fragment type, start offset, end offset and original tag name. Merge adjacent node fragments of the same type into a single node fragment, and record the sub-fragment sequence number in the merged node fragment to obtain a node fragment sequence.
[0009] Preferably, the step of establishing nested hierarchical indexes and same-level adjacency indexes based on the pairing relationship between open and closed labels in the node fragment sequence includes: Set up a stack structure on the node fragment sequence. When an open-label fragment is encountered, push the open-label fragment onto the stack structure and record the current level number. When a closed-label fragment is encountered, match the name of the stack structure with the closed-label fragment. When a name match is successful, pop the corresponding open tag fragment from the stack structure, take the node fragments between the corresponding open tag fragment and the closed tag fragment as a set of child fragments, generate the parent fragment identifier and level number and write them into the nested level index; In the set of child segments with the same parent segment identifier, establish the previous neighbor segment identifier and the next neighbor segment identifier according to the child segment sequence number, and write them into the same-level adjacency index; When a name match fails, a virtual closed segment is generated at the position of the closed tag segment. The virtual closed segment is then attached to the nearest open tag segment in the stack structure, and the nesting level index and the same-level adjacency index are updated.
[0010] Preferably, the step of generating candidate field paths by combining repeated hierarchical jumps and adjacent segments according to nested hierarchical indexes and intra-level adjacency indexes includes: Traverse the nested hierarchical index and extract the hierarchical transition from the parent segment identifier to the child segment identifier in ascending order of the hierarchical number; Extract the preceding and following segment identifiers of the segments at both ends of the hierarchical jump from the same-level adjacency index to form an adjacency segment combination; The occurrence positions of each type of hierarchical transition and adjacent segment combination in the node segment sequence are counted, and hierarchical transitions and adjacent segment combinations with a number of occurrence positions greater than the position threshold are marked as repeating structures; The parent fragment identifier, child fragment identifier, previous neighbor fragment identifier, and next neighbor fragment identifier in the repeating structure are converted into node attribute tokens, hierarchical transfer tokens, and adjacent position tokens, respectively, and then concatenated in the order of their appearance to obtain the candidate field path.
[0011] Preferably, the step of performing hit replay on the candidate field path in the node fragment sequence includes: The candidate field path is split into node attribute tokens, hierarchical transfer tokens, and adjacent position tokens, and a cursor is set in the node fragment sequence according to the token order in the candidate field path; For node attribute tokens, match the tag name, identifier attribute, and class name attribute in the node fragment where the cursor is located and its sub-fragments, and write the matching node fragments to the hit node; For hierarchical transfer tokens, the parent fragment identifier or child fragment identifier relationship between the hit node and the next hit node is verified according to the nested hierarchical index. If the verification fails, the cursor is rolled back. For adjacent position tokens, verify the relationship between the previous or next neighbor segment identifier and the next hit node according to the same-level adjacency index, record the hit continuous segment and text offset, and obtain the set of hit nodes and path span record.
[0012] Preferably, the step of determining the field extraction path by performing conflict folding on the candidate field path based on the coverage relationship between the hit node sets and the length of consecutive segments in the path span record includes: Extract the set of hit nodes for multiple candidate field paths, compare the number of identical hit nodes and the number of different hit nodes among the sets of hit nodes, and generate a coverage relationship; Candidate field paths with more identical hit nodes than different hit nodes in the same set of hit nodes are grouped into the same path group according to the coverage relationship. Extract the length of consecutive segments from the path span records within the path group, and set the candidate field path with the largest consecutive segment length as the group representative path. Sort the group representative path and non-group candidate field paths according to the number of hit nodes, remove candidate field paths whose hit node set is completely contained by the group representative path, and determine the remaining candidate field paths as field extraction paths.
[0013] Preferably, obtaining the source code of the target webpage includes: Receive the Uniform Resource Locator (URL) of the target webpage, send a Hypertext Transfer Protocol (HTTP) request according to the URL, and obtain the initial response content; Identify script reference markers and style reference markers in the initial response content, extract the script content corresponding to the script reference markers, and execute the script content according to the document object interface to obtain the executed document tree; The document tree after execution is associated with the style reference tags in the initial response content to generate the associated document tree; The associated document tree is serialized into the source code of the target webpage according to the tag hierarchy.
[0014] Preferably, when the name matching fails, a virtual closed segment is generated at the position of the closed tag segment, and the virtual closed segment is attached to the nearest open tag segment in the stack structure, including: When a name match fails, read the tag name of the closed tag fragment and search for the open tag fragment with the same tag name from top to bottom in the stack structure; If an open tag segment with the same tag name is found, the open tag segment located above the found open tag segment in the stack structure is identified as the segment to be closed. Before the closing label segment position, virtual closing segments corresponding to the closing segments to be filled are generated in reverse order according to the push order of the closing segments to be filled in the stack structure; Attach the virtual closed segment corresponding to the closed segment to be filled to the closed segment to be filled, and pop the closed segment to be filled from the stack structure.
[0015] Preferably, the step of converting the parent segment identifier, child segment identifier, previous neighbor segment identifier, and subsequent neighbor segment identifier in the repeating structure into node attribute tokens, hierarchical transfer tokens, and adjacent position tokens, respectively, includes: For the parent fragment identifier and child fragment identifier, read the tag name, identifier attribute value and class name attribute value of the corresponding node fragment, and concatenate them into a node attribute token in the order of tag name, identifier attribute value and class name attribute value; For the parent fragment identifier and child fragment identifier, read the level number of the corresponding node fragment, and concatenate them into a level transfer token in the order of parent fragment level number, child fragment level number, parent fragment tag name, and child fragment tag name; For the preceding and following segment identifiers, read the tag name and same-level sequence number of the corresponding node segment, and concatenate them into an adjacent position token in the order of preceding segment tag name, current segment tag name, following segment tag name, and same-level sequence number; Write the node attribute token, hierarchy transfer token, and adjacent position token into the candidate field path according to their positions in the candidate field path, following the repeating structure.
[0016] Preferably, the method of recording hits on consecutive segments and text offsets to obtain a set of hit nodes and a path span record includes: For two adjacent hit nodes in the hit node set, read the end offset and start offset of the two hit nodes in the node segment sequence; If the node segments between the end offset and the start offset are both blank segments, then the two hit nodes will be merged into the same hit contiguous segment. If there is a non-blank segment between the end offset and the start offset, or if the level numbers of the two hit nodes are different, then a new hit continuum is established between the two hit nodes. Write the start node offset, end node offset, text character start position, and text character end position of each hit continuous segment into the path span record, and set the segment number according to the order of the hit continuous segments in the node segment sequence.
[0017] The technical effects and advantages provided by the present invention in the above technical solution are as follows: During the field extraction path generation process, the target webpage source code is segmented according to the start and end positions of tags and the boundaries of text nodes. Comment tags, script sections, and style sections are marked as invisible fragments, ensuring that the node fragment sequence upon which path generation is based only retains tags and text nodes related to the field content. When building nested hierarchical indexes and intra-level adjacency indexes, name matching of opening and closing tag fragments is performed using a stack structure. If a name match fails, an opening tag with the same name is searched in the stack. The opening tag above this opening tag in the stack is taken as the closing fragment to be supplemented. A corresponding virtual closing fragment is generated in reverse before the closing tag fragment position, and the virtual closing fragment is attached to the closing fragment to be supplemented. This processing method does not rely on the browser's implicit correction of tag errors. Even when webpage tags are not closed, misaligned, or abnormally nested, it can still form complete parent fragment identifiers, level numbers, previous neighbor fragment identifiers, and subsequent neighbor fragment identifiers. This ensures that subsequent hierarchical jumps and combinations of adjacent fragments are established on a stable relationship, avoiding candidate path offsets or failure to generate due to incomplete parse trees.
[0018] Candidate field paths consist of node attribute tokens, hierarchical transition tokens, and adjacent position tokens. They are automatically generated by statistically analyzing repeated hierarchical transitions and adjacent segment combinations, and are replayed in the node segment sequence according to the token order. Node attribute tokens match tag names, identifier attributes, and class name attributes; hierarchical transition tokens verify parent-child relationships; and adjacent position tokens verify preceding and following adjacency relationships. Hit playback records the hit nodes, hit consecutive segments, and text offsets. Compared to fixed XPath or CSS selectors, this tokenized path can simultaneously constrain node attributes, hierarchical relationships, and intra-level adjacency relationships, and is adaptable to local node changes in repetitive structures. Conflict folding is performed based on the coverage relationship between the hit node sets and the length of consecutive segments in the path span record. Candidate paths covering many of the same hit nodes are grouped into the same path group, and the candidate path with the longest consecutive segment is selected as the representative path of the group. Candidate paths whose hit node sets are completely contained are removed. This process automatically retains paths with continuous coverage from multiple candidate field paths, suppresses noisy paths that only cover local segments, and reduces the mixing of irrelevant content and field omissions in the field extraction results. Attached Figure Description
[0019] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this invention. For those skilled in the art, other drawings can be obtained based on these drawings.
[0020] Figure 1 This is a flowchart of a method for generating field extraction paths based on webpage structure analysis; Figure 2 This is a flowchart of the process for obtaining the source code of the target webpage and segmenting node fragments. Detailed Implementation
[0021] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0022] See Figure 1This invention provides a method for generating field extraction paths based on webpage structure analysis, comprising: obtaining the source code of a target webpage; segmenting the target webpage source code according to the start and end positions of tags and the boundaries of text nodes to obtain a sequence of node fragments; establishing a nested hierarchical index and a same-level adjacency index based on the pairing relationship between open and closed tags in the node fragment sequence, wherein the nested hierarchical index records the parent fragment identifier and the hierarchical number, and the same-level adjacency index records the identifier of the preceding neighbor fragment and the identifier of the following neighbor fragment; generating candidate field paths by combining repeated hierarchical transitions and adjacency fragments according to the nested hierarchical index and the same-level adjacency index, wherein each candidate field path consists of a node attribute token, a hierarchical transition token, and an adjacent position token; performing a hit replay on the candidate field paths in the node fragment sequence, recording the hit nodes, hit consecutive segments, and text offsets to obtain a set of hit nodes and a path span record; and performing conflict folding on the candidate field paths based on the coverage relationship between the sets of hit nodes and the length of consecutive segments in the path span record to determine the field extraction path.
[0023] In specific implementation, please refer to Figure 2 The system receives the Uniform Resource Locator (URI) of the target webpage, sends a Hypertext Transfer Protocol (HTTP) request according to the URI, and obtains the initial response content. When receiving the URI, it reads the URI from the task queue. The URI contains the protocol type, host address, port number, and resource path. When sending the HTTP request according to the URI, it selects the transport layer protocol based on the protocol type in the URI, establishes a connection based on the host address and port number, constructs an HTTP request message containing a request line, request header, and request body, sends the request message to the target host, and receives the HTTP response message returned by the target host, using the response body as the initial response content.
[0024] When identifying script and style reference tags in the initial response content, a tag scan is performed on the initial response content. Tags with the name "script" are identified as script reference tags, and tags with the name "link" and a "rel" attribute value of "stylesheet" are identified as style reference tags. When extracting the script content corresponding to the script reference tags, it is determined whether the script reference tag contains a "src" attribute. If the script reference tag contains a "src" attribute, the "src" attribute value is read, and the external script resource content is obtained based on the "src" attribute value and used as the script content. If the script reference tag does not contain a "src" attribute, the character content between the start and end tags of the script reference tag is read and used as the script content. When executing the script content according to the Document Object Interface (DOM) protocol, an initial document tree is created in the DOM parser. The script content is injected into the script execution environment of the DOM parser, and the script execution environment executes the DOM operations in the script content. DOM operations include node creation, node deletion, node attribute modification, and event binding. After execution, the executed document tree is obtained.
[0025] When associating the post-execution document tree with the style reference tags in the initial response content, the `href` attribute value in the style reference tag is read, and the external stylesheet content is obtained based on the `href` attribute value. The external stylesheet content is parsed into style rules, which contain selectors and declaration blocks. Each node in the post-execution document tree is traversed, and the selectors in the style rules are matched with the nodes in the post-execution document tree. The matched declaration blocks are associated with the corresponding nodes in the post-execution document tree, generating the associated post-execution document tree. The associated post-execution document tree contains style information for each node, including color, font, border, and display attributes.
[0026] When serializing the associated document tree into the target webpage source code according to the tag hierarchy, the associated document tree is traversed in depth-first order, starting from the root node. For each element node in the associated document tree, an opening tag string is generated, containing a less-than sign, tag name, attribute name, and attribute value. The attribute name and attribute value are connected by an equal sign, and the attribute value is enclosed in double quotes. For each text node in the associated document tree, a text string is generated, which is the character content of the text node. For each element node in the associated document tree, a closing tag string is generated, containing a less-than sign, a forward slash, tag name, and a greater-than sign. The opening tag string, text string, and closing tag string are concatenated in the traversal order to obtain the target webpage source code.
[0027] When splitting the source code of a target webpage according to tag start and end positions and text node boundaries, comment markers, script intervals, and style intervals in the source code of the target webpage are identified. When identifying comment markers, a search is performed in the source code of the target webpage for intervals of characters that start with <!-- and end with -->, and all intervals of characters between <!-- and --> are marked as comment markers. When identifying script intervals, a search is performed in the source code of the target webpage for intervals of characters that start with a <script open tag and end with a closing tag, and all intervals of characters between the <script open tag and the closing tag are marked as script intervals. When identifying style intervals, a search is performed in the source code of the target webpage for intervals of characters that start with a <style open tag and end with a closing tag, and all intervals of characters between the <style open tag and the closing tag are marked as style intervals. The comment markers, script intervals, and style intervals are marked as invisible segments, which do not participate in the subsequent nested hierarchy indexing and same-level adjacency indexing of the node segment sequence.
[0028] Split points are established for the start position of each open tag, the end position of each closing tag, and the boundaries of consecutive text characters outside the invisible segments. In a specific implementation, each character offset in the source code of the target webpage is scanned; when the character at the character offset is a less-than sign and the next character is not a slash or an exclamation mark, the character offset is recorded as the start position of an open tag; when the character at the character offset is a greater-than sign, the character offset is recorded as the end position of a closing tag; when the character at the character offset is neither a less-than sign nor a greater-than sign, it is determined whether the character offset is the first or last character of consecutive text characters, and the offsets of the first and last characters of the consecutive text characters are recorded as the boundaries of the consecutive text characters. The recorded start positions of open tags, end positions of closing tags, and boundaries of consecutive text characters are used as split points.
[0029] The source code of the target webpage is split into node segments according to the split points. During splitting, the character content between two adjacent split points is taken as one node segment, which carries a segment type, a start offset, an end offset, and an original tag name. The segment type is determined based on the first and last characters of the node segment: if the first character of the node segment is a less-than sign, the last character is a greater-than sign, and the second character is a slash, the segment type is a closing tag type; if the first character of the node segment is a less-than sign, the last character is a greater-than sign, and the second character is not a slash, the segment type is an open tag type; if the first character of the node segment is not a less-than sign, the segment type is a text type; if the node segment belongs to an invisible segment, the segment type is an invisible type. The start offset is the offset of the first character of the node segment in the source code of the target webpage, and the end offset is the offset of the last character of the node segment in the source code of the target webpage. The original tag name is the tag name in the node segment after removing the less-than sign, greater-than sign, and slash.
[0030] Merge adjacent node fragments of the same type into a single node fragment. During merging, sequentially check the fragment types of adjacent node fragments according to their sequence. If two adjacent node fragments have the same fragment type, merge them into one node fragment. The merged node fragment will have the same fragment type as the two adjacent fragments. The starting offset of the merged node fragment will be the starting offset of the preceding node fragment, and the ending offset will be the ending offset of the following node fragment. Record the sub-fragment sequence number in the merged node fragment, starting from 1 and incrementing sequentially. Arrange the merged node fragment and the unmerged node fragments in their original order to obtain the node fragment sequence.
[0031] When merging text-type node fragments, multiple consecutive text node fragments are merged into one text node fragment. The merged text node fragment carries multiple sub-fragment sequence numbers, each of which corresponds to the text node fragment before merging. When merging open-label type node fragments, multiple consecutive open-label type node fragments are merged into one open-label type node fragment.
[0032] In practice, nested hierarchical indexes and same-level adjacency indexes are established based on the pairing relationship between open and closed labels in the node fragment sequence. A stack structure is set up on the node fragment sequence. The stack structure is a last-in-first-out data container, and each storage unit in the stack structure stores an open-label fragment and the current level number. During the initialization phase, the stack structure is empty.
[0033] When an open-label segment is encountered, it is pushed onto the stack and the current level number is recorded. The current level number is determined by the number of existing storage units in the stack; if the number of existing storage units in the stack is N, then the current level number is N+1. The open-label segment and the current level number are then pushed onto the top of the stack as a single storage unit. When the first open-label segment in the node segment sequence is pushed onto the stack, the number of storage units in the stack is 0, and the current level number is recorded as 1.
[0034] When a closing tag fragment is encountered, the stack structure is matched against the closing tag fragment by name. During name matching, the original tag name of the closing tag fragment is read, and the original tag name of the opening tag fragment in the top memory location of the stack structure is also read. If the original tag name of the closing tag fragment is the same as the original tag name of the opening tag fragment in the top memory location of the stack structure, the name match is successful. If the original tag name of the closing tag fragment is different from the original tag name of the opening tag fragment in the top memory location of the stack structure, the name match fails.
[0035] When a name match is successful, the corresponding opening tag fragment is popped from the stack structure. The process of popping the opening tag fragment is as follows: the top storage unit of the stack structure is removed, and the removed storage unit contains the corresponding opening tag fragment and its corresponding level number. The node fragments between the corresponding opening tag fragment and the closing tag fragment are treated as a set of child fragments. The set of child fragments consists of all node fragments located between the corresponding opening tag fragment and the closing tag fragment in the node fragment sequence. A parent fragment identifier and level number are generated and written to the nested level index. The parent fragment identifier is the fragment identifier of the corresponding opening tag fragment, and the level number is the corresponding level number. In the nested level index, the parent fragment identifier is recorded as the fragment identifier of the corresponding opening tag fragment, and the level number is recorded as the corresponding level number. Simultaneously, the fragment identifier of the closing tag fragment is recorded in the nested level index, and an association is established between the fragment identifier of the closing tag fragment and the fragment identifier of the corresponding opening tag fragment.
[0036] In a set of sub-segments with the same parent segment identifier, establish the preceding and following segment identifiers according to the sub-segment sequence number and write them into the same-level adjacency index. For each node segment in the sub-segment set, determine the corresponding sub-segment sequence number within the sub-segment set. For the i-th node segment in the sub-segment set, if i is greater than 1, the preceding segment identifier of the i-th node segment is the segment identifier of the (i-1)-th node segment; if i is less than the total number of node segments in the sub-segment set, the following segment identifier of the i-th node segment is the segment identifier of the (i+1)-th node segment. Write the preceding and following segment identifiers into the same-level adjacency index. Each record in the same-level adjacency index contains the node segment's segment identifier, preceding segment identifier, and following segment identifier. For the first node segment in the sub-segment set, the preceding segment identifier is null; for the last node segment in the sub-segment set, the following segment identifier is null.
[0037] When the sub-fragment set contains open-label and closed-label fragments with deeper nesting levels, the nested node fragments also participate in the establishment of the previous and next neighbor fragment identifiers, and the nested node fragments also occupy positions in the node fragment sequence.
[0038] When a name match fails, a virtual closed segment is generated at the position of the closed tag segment. The virtual closed segment is then attached to the nearest open tag segment in the stack structure, and the nesting level index and the same-level adjacency index are updated.
[0039] When a name match fails, the tag name of the closing tag fragment is read, and an open tag fragment with the same tag name is searched for in the stack structure from top to bottom. During the search from top to bottom, the original tag name of the open tag fragment in each memory unit of the stack structure is read sequentially and compared with the tag name of the closing tag fragment until an open tag fragment with the same original tag name as the closing tag fragment is found. If an open tag fragment with the same tag name is found, the open tag fragments in the stack structure above the found open tag fragment are identified as the closing tags to be filled. The closing tags to be filled are all the open tag fragments in the stack structure above the found open tag fragments; there can be one or more closing tags to be filled.
[0040] Before the closing label segment position, virtual closing segments corresponding to the closing segments to be supplemented are generated in reverse order according to the pushing order of the closing segments in the stack structure. The pushing order of the closing segments to be supplemented in the stack structure is from the bottom of the stack to the top. During reverse generation, starting from the closing segment to be supplemented at the top of the stack structure, virtual closing segments are generated for each closing segment to be supplemented in turn. The label name of the virtual closing segment is the same as the original label name of the corresponding closing segment to be supplemented. The virtual closing segment is a closing label segment that is manually inserted into the node segment sequence. The segment type of the virtual closing segment is closing label type, and the start offset and end offset are both set to the offset before the closing label segment position.
[0041] The virtual closed segment corresponding to the segment to be closed is attached to the segment to be closed. The attachment process is as follows: In the nested hierarchical index, the segment identifier of the segment to be closed is used as the parent segment identifier, and the segment identifier of the virtual closed segment is used as the child segment identifier, and written into the level number. At the same time, in the same-level adjacency index, the previous neighbor segment identifier and the next neighbor segment identifier relationship are established between the virtual closed segment and other child segments of the segment to be closed.
[0042] Pop the unfinished closing segments from the stack structure. The popping order is from top to bottom of the stack. For each unfinished closing segment popped, its corresponding virtual closing segment is attached to the original unfinished closing segment. After all unfinished closing segments are popped, the stack structure retains the unlabeled segments with the same label name.
[0043] When updating nested level indexes and same-level adjacency indexes, for virtual closed segments, the segment identifier of the virtual closed segment needs to be written into the nested level index, and the segment identifier of the virtual closed segment needs to be written into the same-level adjacency index, maintaining the same index format as the real node segments.
[0044] If a name match fails, and no open tag segment with the same tag name is found after searching from the top to the bottom of the stack, the corresponding closed tag segment is ignored, no virtual closed segment is generated, and the next node segment in the node segment sequence is processed.
[0045] In practice, candidate field paths are generated by combining recurring hierarchical transitions and adjacent segments based on nested hierarchical indexes and intra-level adjacency indexes. The nested hierarchical index is traversed, and hierarchical transitions from the parent segment identifier to the child segment identifier are extracted in ascending order of hierarchical number. When traversing the nested hierarchical index, each index record is read, and each record contains the parent segment identifier, child segment identifier, and hierarchical number. When extracting hierarchical transitions in ascending order of hierarchical number, the process starts with the index record with the smallest hierarchical number and proceeds sequentially through the records with larger hierarchical numbers. For each index record, the parent segment identifier and child segment identifier are extracted; these two identifiers together constitute one hierarchical transition. For example, if the parent segment identifier of an index record is node segment identifier A and the child segment identifier is node segment identifier B, then a hierarchical transition occurs from node segment identifier A to node segment identifier B.
[0046] The hierarchical transitions corresponding to these index records are considered to be of the same type. The extraction result of the same type of hierarchical transition is a hierarchical transition set, which records the parent segment identifier, the child segment identifier set, and the hierarchical number.
[0047] Extract the preceding and following fragment identifiers from the two ends of the hierarchical jump in the same-level adjacency index to form an adjacency fragment combination. For a single hierarchical jump, the two ends of the hierarchical jump are the node fragment corresponding to the parent fragment identifier and the node fragment corresponding to the child fragment identifier. In the same-level adjacency index, search for the records of the node fragments corresponding to the parent fragment identifier and the node fragments corresponding to the child fragment identifier, respectively. Read the preceding and following fragment identifiers from the records of the node fragments corresponding to the parent fragment identifier, and read the preceding and following fragment identifiers from the records of the node fragments corresponding to the child fragment identifier. Combine the preceding and following fragment identifiers of the node fragments corresponding to the parent fragment identifier and the preceding and following fragment identifiers of the node fragments corresponding to the child fragment identifier to form an adjacency fragment combination. The adjacency fragment combination contains four components: parent preceding fragment identifier, parent following fragment identifier, child preceding fragment identifier, and child following fragment identifier.
[0048] When forming a combination of adjacent segments, if the node segment corresponding to the parent segment identifier does not have a preceding segment identifier in the same-level adjacency index, then the parent preceding segment identifier is set to null; if the node segment corresponding to the parent segment identifier does not have a following segment identifier in the same-level adjacency index, then the parent following segment identifier is set to null. If the node segment corresponding to the child segment identifier does not have a preceding segment identifier in the same-level adjacency index, then the child preceding segment identifier is set to null; if the node segment corresponding to the child segment identifier does not have a following segment identifier in the same-level adjacency index, then the child following segment identifier is set to null.
[0049] When counting the occurrence positions of each level transition and adjacent segment combination in the node segment sequence, the same level transition and its corresponding adjacent segment combination are treated as a single combination structure. In the node segment sequence, the positions of each level transition are scanned sequentially, and the adjacent segment combination corresponding to each level transition is recorded. If multiple positions have the same level transition and the same adjacent segment combination, then these positions belong to the same level transition and adjacent segment combination. For the same level transition and adjacent segment combination, the number of positions in the node segment sequence that it appears in is counted. The number of positions is equal to the number of times that level transition and adjacent segment combination appears in the node segment sequence.
[0050] Hierarchical transitions with a number of occurrences exceeding a position threshold, combined with adjacent segments, are marked as repeating structures. The position threshold is determined based on the minimum number of occurrences a repeating structure should satisfy. Let the first... The number of occurrence positions of hierarchical transitions and adjacent segment combinations in the node segment sequence is: The location threshold is When certain conditions are met, the first The combination of hierarchical transitions and adjacent segments is labeled as a repeating structure. The conditions are:
[0051] in, This indicates the type number of the hierarchical transition and adjacent segment combination. The value is a positive integer. Starting from 1, increment sequentially. Indicates the first The number of locations where hierarchical transitions and adjacent segment combinations occur. This was obtained through the statistical process described above. Indicates the location threshold. The value of is an integer greater than or equal to 2. The basis for setting it to 2 is: when the same hierarchical transition and adjacent segment combination occurs at least twice, it can be considered that the hierarchical transition and adjacent segment combination constitutes a repeating structure in the node segment sequence. Therefore, [the following is a separate, unrelated statement:] Set to 2. When hour, If it is not true, it is not marked as a repeated structure; when hour, If true, it is marked as a repeating structure. This ensures that the repeating structure contains at least three occurrences.
[0052] The parent fragment identifier, child fragment identifier, previous neighbor fragment identifier, and subsequent neighbor fragment identifier in the repeating structure are converted into node attribute tokens, hierarchy transfer tokens, and adjacent position tokens, respectively. In specific implementation, for the parent fragment identifier and child fragment identifier, the label name, identifier attribute value, and class name attribute value of the corresponding node fragment are read and concatenated into a node attribute token in the order of label name, identifier attribute value, and class name attribute value. When reading the label name of the corresponding node fragment, the original label name of the node fragment is read, which is obtained from the node fragment sequence. When reading the identifier attribute value, the id attribute is searched for in the opening label string of the node fragment, and its attribute value is obtained. When reading the class name attribute value, the class attribute is searched for in the opening label string of the node fragment, and its attribute value is obtained. When concatenating in the order of label name, identifier attribute value, and class name attribute value, a separator is added after the label name and after the identifier attribute value, using a vertical bar character as the separator. If the identifier attribute value is empty, an empty string is written in the identifier attribute value position.
[0053] For both parent and child fragment identifiers, the level number of the corresponding node fragment is read and concatenated into a level transfer token in the order of parent fragment level number, child fragment level number, parent fragment tag name, and child fragment tag name. When reading the level number of the corresponding node fragment, the level numbers of the node fragments corresponding to the parent and child fragment identifiers are obtained from the nested level index. The parent fragment level number is the level number of the node fragment corresponding to the parent fragment identifier, and the child fragment level number is the level number of the node fragment corresponding to the child fragment identifier. The parent fragment tag name is the original tag name of the node fragment corresponding to the parent fragment identifier, and the child fragment tag name is the original tag name of the node fragment corresponding to the child fragment identifier. When concatenating in the order of parent fragment level number, child fragment level number, parent fragment tag name, and child fragment tag name, a vertical bar character is used as a separator between each component.
[0054] For the preceding and following fragment identifiers, read the label name and sibling index of the corresponding node fragment, and concatenate them into an adjacent position token in the order of preceding fragment label name, current fragment label name, following fragment label name, and sibling index. When reading the label name of the corresponding node fragment, read the original label name of the node fragment corresponding to the preceding fragment identifier, the original label name of the node fragment corresponding to the current fragment identifier, and the original label name of the node fragment corresponding to the following fragment identifier. When reading the sibling index, read the sequence number of the node fragment corresponding to the current fragment identifier in the sibling adjacency index. The sibling index is the positional sequence number of the node fragment in the set of child fragments with the same parent fragment identifier. When concatenating in the order of preceding fragment label name, current fragment label name, following fragment label name, and sibling index, use a vertical bar character as a separator between the components.
[0055] Write the node attribute token, hierarchical transition token, and adjacent position token into the candidate field path according to their positions in the repeating structure. For each repeating structure, determine the order of the node attribute token, hierarchical transition token, and adjacent position token within the repeating structure. The node attribute token corresponds to the parent fragment identifier and child fragment identifier, the hierarchical transition token corresponds to the parent fragment identifier and child fragment identifier, and the adjacent position token corresponds to the previous neighbor fragment identifier and the next neighbor fragment identifier. Concatenate the node attribute token, hierarchical transition token, and adjacent position token sequentially according to the hierarchical transition order in the repeating structure to obtain the candidate field path. Use spaces as separators between tokens in the candidate field path.
[0056] The writing order of node attribute tokens, hierarchical transition tokens, and adjacent position tokens is consistent with the position of the repeating structure in the candidate field path. If the repeating structure contains a parent fragment identifier, a previous neighbor fragment identifier, and a child fragment identifier, the corresponding token order is: parent node attribute token, adjacent position token, child node attribute token, hierarchical transition token. Each hierarchical transition corresponds to a candidate field path, and the token order of the candidate field path is determined according to the actual position of each fragment identifier in the repeating structure.
[0057] In practical implementation, when replaying the hits of candidate field paths in the node fragment sequence, the candidate field paths are split into node attribute tokens, hierarchical transfer tokens, and adjacent position tokens. During splitting, the space separators in the candidate field paths are read, dividing the candidate field paths into multiple tokens according to the space separators. For each token, the number and position of the vertical bar separators within the token are read. If the number of vertical bar separators within the token is 2 and the first segment is a label name, then the token is a node attribute token; if the number of vertical bar separators within the token is 3 and the first segment is a hierarchical number, then the token is a hierarchical transfer token; if the number of vertical bar separators within the token is 3 and the first segment is a label name, then the token is an adjacent position token.
[0058] The cursor is set in the node fragment sequence according to the token order in the candidate field path. The token order in the candidate field path is determined when the candidate field path is generated, and the node attribute tokens, hierarchy transfer tokens, and adjacent position tokens are arranged according to the writing order in the candidate field path. When setting the cursor in the node fragment sequence, the initial position of the cursor is set to the first node fragment in the node fragment sequence, and the cursor points to the currently processed node fragment.
[0059] For node attribute tokens, match the tag name, identifier attribute, and class name attribute within the node fragment containing the cursor and its sub-fragments. The node attribute token contains the tag name, identifier attribute value, and class name attribute value, separated by a vertical bar. When matching the tag name within the node fragment containing the cursor, read the original tag name of the node fragment and compare it with the tag name in the node attribute token; if they match, the tag name is matched. When matching the identifier attribute within the node fragment containing the cursor and its sub-fragments, search for the id attribute in the opening tag string of the node fragment and its sub-fragments. If the opening tag string contains the id attribute and the id attribute value is the same as the identifier attribute value in the node attribute token, the identifier attribute is matched; if the identifier attribute value in the node attribute token is an empty string, the identifier attribute is not matched, and the identifier attribute match passes directly. When matching the class name attribute in the node fragment and its sub-fragments where the cursor is located, the `class` attribute is searched in the opening tag string of the node fragment and its sub-fragments. If the opening tag string contains the `class` attribute and the value of the `class` attribute is the same as the value of the class name attribute in the node attribute token, then the class name attribute match is successful. If the value of the class name attribute in the node attribute token is an empty string, then the class name attribute is not matched, and the class name attribute match is successful directly. Node fragments that match the tag name, the identifier attribute, and the class name attribute are written to the hit node. The hit node is the node fragment in the node fragment sequence that corresponds to the node attribute token.
[0060] The child fragments of the node fragment where the cursor is located are all node fragments whose parent fragment identifier in the nested level index is equal to the fragment identifier of the node fragment where the cursor is located. When matching node attribute tokens in the node fragment where the cursor is located and its child fragments, the node fragment where the cursor is located and the child fragments belonging to the node fragment where the cursor is located recorded in the nested level index are traversed, and for each traversed node fragment, tag name matching, identifier attribute matching, and class name attribute matching are performed.
[0061] For hierarchical transfer tokens, the parent or child fragment identifier relationship between the hit node and the next hit node is verified according to the nested hierarchical index. The hierarchical transfer token contains the parent fragment hierarchical number, child fragment hierarchical number, parent fragment label name, and child fragment label name, separated by vertical bars. During hit playback, the hierarchical transfer token verification is triggered when the cursor moves from the hit node to the next hit node. During verification, the fragment identifiers of the hit node and the next hit node are searched in the nested hierarchical index. It is determined whether the fragment identifier of the hit node is the parent fragment identifier corresponding to the fragment identifier of the next hit node, or whether the fragment identifier of the next hit node is the child fragment identifier corresponding to the fragment identifier of the hit node. If a parent-child fragment identifier relationship exists between the fragment identifiers of the hit node and the next hit node, the hierarchical transfer token verification passes, and the cursor remains at the next hit node position. If there is no parent-child fragment identifier relationship between the fragment identifier of the hit node and the fragment identifier of the next hit node, the hierarchical transfer token verification fails, the cursor is rolled back to the position of the hit node before the hierarchical transfer token processing.
[0062] For adjacent position tokens, the relationship between the preceding or following segment identifiers of the hit node and the next hit node is verified according to the same-level adjacency index. The adjacent position token contains the preceding segment label name, the current segment label name, the following segment label name, and the same-level sequence number, with components separated by vertical bars. During hit playback, adjacent position token verification is triggered when the cursor moves from the hit node to the next hit node. During verification, the preceding and following segment identifiers corresponding to the segment identifier of the hit node are searched in the same-level adjacency index. It is then determined whether the segment identifier of the next hit node is equal to the preceding segment identifier corresponding to the segment identifier of the hit node, or whether the segment identifier of the next hit node is equal to the following segment identifier corresponding to the segment identifier of the hit node. If the segment identifier of the next hit node is equal to the preceding segment identifier corresponding to the segment identifier of the hit node, or equal to the following segment identifier corresponding to the segment identifier of the hit node, the adjacent position token verification passes, and the hit contiguous segment and text offset are recorded. If the fragment identifier of the next hit node is not equal to the previous fragment identifier and not equal to the next fragment identifier of the hit node, the adjacent position token verification fails, the cursor is rolled back to the position of the hit node before the adjacent position token processing.
[0063] When the cursor rolls back, the rollback position is determined based on the number of tokens that have passed validation in the candidate field path. If the hierarchical transfer token validation fails, the cursor rolls back to the position of the most recent write hit node before the current hierarchical transfer token; if the adjacent position token validation fails, the cursor rolls back to the position of the most recent write hit node before the current adjacent position token.
[0064] When recording hit contiguous segments and text offsets, for two adjacent hit nodes in the hit node set, read the end offset and start offset of the two hit nodes in the node segment sequence. The hit node set consists of all hit nodes written during this hit playback process. Two adjacent hit nodes are two hit nodes in the hit node set that are adjacent in the writing order. When reading the end offset, read the end offset of the previous hit node; when reading the start offset, read the start offset of the next hit node. If the node segments between the end offset of the previous hit node and the start offset of the next hit node are both blank segments, then the two hit nodes are merged into the same hit contiguous segment. Blank segments are node segments in the node segment sequence whose segment type is text and whose character length is 0 after removing whitespace characters. If there are non-blank segments between the end offset of the previous hit node and the start offset of the next hit node, or if the level numbers of the two hit nodes are different, then a new hit contiguous segment is established between the two hit nodes. Non-whitespace fragments are node fragments in the node fragment sequence whose fragment type is text and whose character length is greater than 0 after removing whitespace characters. The level numbers of the two hit nodes are read from the nested level index.
[0065] Write the start node offset, end node offset, start position of the text character, and end position of the text character for each hit contiguous segment into the path span record, and set the segment number according to the order of the hit contiguous segments in the node segment sequence. Each hit contiguous segment in the path span record corresponds to one record, and the record contains the segment number, start node offset, end node offset, start position of the text character, and end position of the text character. When writing to the path span record, the length of each hit contiguous segment can be calculated, let the length be the first... The segment number of the hit consecutive segments is , No. The length of each hit in a consecutive segment is , No. The offset of the starting node of each hit sequence is , No. The offset of the end node of each hit sequence is The formula for calculating the length of a continuous segment is:
[0066] in, Indicates the segment number of the consecutive segments hit. The value is a positive integer. Starting from 1, increment sequentially. Indicates the first The length of a consecutive segment that hits the target. The unit is the number of node fragments. The above formula is used for calculation. Indicates the first The offset of the starting node of each hit sequence. Read from the path span record. Indicates the first The offset of the end node of each hit sequence. Read from the path span record.
[0067] The start and end positions of the text characters are determined based on the start offset of the text characters in the first node segment and the end offset of the text characters in the last node segment of the hit contiguous segment. The start position of the text characters is the start offset of the text characters in the first node segment of the hit contiguous segment in the target webpage source code, and the end position of the text characters is the end offset of the text characters in the last node segment of the hit contiguous segment in the target webpage source code.
[0068] In practice, based on the coverage relationship between the hit node sets and the length of consecutive segments in the path span record, conflict folding is performed on the candidate field paths to determine the field extraction path. After completing the hit replay of the candidate field paths in the node segment sequence, the hit node set and path span record corresponding to each candidate field path are obtained. The elements in the hit node set are the segment identifiers of the node segments written to the hit nodes during the hit replay process. The path span record contains the segment number, start node offset, end node offset, text character start position, and text character end position of each hit consecutive segment.
[0069] Extract the hit node sets for multiple candidate field paths. Store the hit node set for each candidate field path separately, with each candidate field path corresponding to one hit node set. The node fragment identifiers in the hit node sets are arranged according to the writing order during the hit playback process.
[0070] Compare the number of identical hit nodes and the number of different hit nodes among the sets of hit nodes. Let the first set be... The set of hit nodes for each candidate field path is , No. The set of hit nodes for each candidate field path is ,in and Both represent the path numbers of the candidate fields. and The values of are all positive integers, and . Indicates the first The set of hit nodes corresponding to each candidate field path. Indicates the first The set of hit nodes corresponding to each candidate field path. Let... express and The number of identical hit nodes between them The value of is a non-negative integer. Through calculation and The number of elements in the intersection of the two sets is obtained. Let's assume... express and The different number of hit nodes between them The value of is a non-negative integer. Through calculation and The number of elements in the union set minus and The number of elements in the intersection of the given set is obtained. The generation of the first set is achieved when certain conditions are met. The path of the candidate field and the first Coverage relationship between candidate field paths. The conditions are:
[0071] calculate and When the intersection is found, traverse For each element in the array, determine whether the element exists simultaneously with the other elements. If a matching node exists, increment the count by one. Calculate... and When the union of the sets is reached, the set will be... and All elements in the union are merged into a single set, and duplicate elements are removed. The number of distinct matching nodes is equal to the number of elements in the union minus the number of elements in the intersection.
[0072] Candidate field paths with more identical hit nodes than different hit nodes across sets of hit nodes are grouped into the same path group based on their coverage relationships. When grouping into the same path group, a coverage relationship table is constructed. Each record in the table contains a candidate field path number and a list of candidate field path numbers that have a coverage relationship with that candidate field path. Starting with an ungrouped candidate field path, candidate field paths that have a coverage relationship with the current candidate field path are added to the current path group. This process continues layer by layer, adding candidate field paths that have a coverage relationship with newly added candidate field paths until no new candidate field paths can be added, completing the grouping of a path group. The above process is repeated for the remaining ungrouped candidate field paths until all candidate field paths have been grouped into their corresponding path groups.
[0073] Extract the length of consecutive segments from the path span records within each path group. For each candidate field path in each path group, read the path span record of the corresponding candidate field path, calculate the length of each hit consecutive segment, and sum the lengths of all hit consecutive segments of the corresponding candidate field path to obtain the total length of consecutive segments. Set the candidate field path with the largest total length of consecutive segments as the group representative path. If multiple candidate field paths in a path group have the same total length of consecutive segments, select the candidate field path with the largest number of elements in the hit node set as the group representative path.
[0074] When calculating the sum of the lengths of consecutive segments in the candidate field path, the start node offset and end node offset of each hit consecutive segment are read from the path span record. The length of the consecutive segment is equal to the end node offset minus the start node offset plus 1. If the path span record contains multiple hit consecutive segments, the length of each hit consecutive segment is calculated separately, and the lengths of all consecutive segments are added together.
[0075] Sort the group representative path and the non-group candidate field path according to the number of hit nodes. The number of hit nodes is the number of elements in the set of hit nodes corresponding to the candidate field path. Treat each group representative path and each non-group candidate field path as objects to be sorted, and arrange them in descending order of the number of hit nodes to obtain the sorting result.
[0076] Remove candidate field paths whose hit node set is completely contained in the group representative path. During removal, iterate through each non-group-internal candidate field path and determine whether its hit node set is completely contained in the hit node set of any group representative path. Complete containment means that every element in the hit node set of the non-group-internal candidate field path exists in the hit node set of the group representative path. If complete containment is true, remove the non-group-internal candidate field path from the candidate field path set. If complete containment is false, retain the non-group-internal candidate field paths. The remaining candidate field paths are then determined as field extraction paths.
[0077] Group representative paths themselves are not removed. All group representative paths and non-intra-group candidate field paths that have not been removed are used as field extraction paths. If the set of hit nodes for a non-intra-group candidate field path is completely contained by multiple group representative paths, it is removed only once, and the final field extraction paths do not contain duplicate candidate field paths.
[0078] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application.
Claims
1. A method for generating field extraction paths based on webpage structure analysis, characterized in that, include: Obtain the source code of the target webpage, and segment the source code of the target webpage according to the start and end positions of tags and the boundaries of text nodes to obtain a sequence of node fragments; Based on the pairing relationship between open and closed labels in the node fragment sequence, nested hierarchical index and same-level adjacency index are established. The nested hierarchical index records the parent fragment identifier and level number, and the same-level adjacency index records the previous neighbor fragment identifier and the next neighbor fragment identifier. Based on nested hierarchical indexes and same-level adjacency indexes, candidate field paths are generated by combining repeated hierarchical jumps and adjacency fragments. Each candidate field path consists of node attribute tokens, hierarchical transfer tokens, and adjacent position tokens. The candidate field path is replayed in the node fragment sequence to record the hit nodes, hit continuous segments and text offsets, and obtain the set of hit nodes and path span records. Based on the coverage relationship between the hit node sets and the length of continuous segments in the path span record, conflict folding is performed on the candidate field path to determine the field extraction path.
2. The method for generating field extraction paths based on webpage structure analysis according to claim 1, characterized in that, The method of segmenting the target webpage source code according to the start and end positions of tags and the boundaries of text nodes includes: Identify comment tags, script sections, and style sections in the source code of the target webpage, and mark comment tags, script sections, and style sections as invisible fragments; Establish segmentation points for each open tag start position, close tag end position, and continuous text character boundary outside of the invisible segment; The target webpage source code is divided into node fragments according to the split points. Each node fragment carries the fragment type, start offset, end offset and original tag name. Merge adjacent node fragments of the same type into a single node fragment, and record the sub-fragment sequence number in the merged node fragment to obtain a node fragment sequence.
3. The method for generating field extraction paths based on webpage structure analysis according to claim 1, characterized in that, The step of establishing nested hierarchical indexes and same-level adjacency indexes based on the pairing relationship between open and closed labels in the node fragment sequence includes: Set up a stack structure on the node fragment sequence. When an open-label fragment is encountered, push the open-label fragment onto the stack structure and record the current level number. When a closed-label fragment is encountered, match the name of the stack structure with the closed-label fragment. When a name match is successful, pop the corresponding open tag fragment from the stack structure, take the node fragments between the corresponding open tag fragment and the closed tag fragment as a set of child fragments, generate the parent fragment identifier and level number and write them into the nested level index; In the set of child segments with the same parent segment identifier, establish the previous neighbor segment identifier and the next neighbor segment identifier according to the child segment sequence number, and write them into the same-level adjacency index; When a name match fails, a virtual closed segment is generated at the position of the closed tag segment. The virtual closed segment is then attached to the nearest open tag segment in the stack structure, and the nesting level index and the same-level adjacency index are updated.
4. The method for generating field extraction paths based on webpage structure analysis according to claim 1, characterized in that, The step of generating candidate field paths by combining repeated hierarchical jumps and adjacent segments according to nested hierarchical indexes and intra-level adjacency indexes includes: Traverse the nested hierarchical index and extract the hierarchical transition from the parent segment identifier to the child segment identifier in ascending order of the hierarchical number; Extract the preceding and following segment identifiers of the segments at both ends of the hierarchical jump from the same-level adjacency index to form an adjacency segment combination; The occurrence positions of each type of hierarchical transition and adjacent segment combination in the node segment sequence are counted, and hierarchical transitions and adjacent segment combinations with a number of occurrence positions greater than the position threshold are marked as repeating structures; The parent fragment identifier, child fragment identifier, previous neighbor fragment identifier, and next neighbor fragment identifier in the repeating structure are converted into node attribute tokens, hierarchical transfer tokens, and adjacent position tokens, respectively, and then concatenated in the order of their appearance to obtain the candidate field path.
5. The method for generating field extraction paths based on webpage structure analysis according to claim 1, characterized in that, The process of replaying the hits on candidate field paths within the node fragment sequence includes: The candidate field path is split into node attribute tokens, hierarchical transfer tokens, and adjacent position tokens, and a cursor is set in the node fragment sequence according to the token order in the candidate field path; For node attribute tokens, match the tag name, identifier attribute, and class name attribute in the node fragment where the cursor is located and its sub-fragments, and write the matching node fragments to the hit node; For hierarchical transfer tokens, the parent fragment identifier or child fragment identifier relationship between the hit node and the next hit node is verified according to the nested hierarchical index. If the verification fails, the cursor is rolled back. For adjacent position tokens, verify the relationship between the previous or next neighbor segment identifier and the next hit node according to the same-level adjacency index, record the hit continuous segment and text offset, and obtain the set of hit nodes and path span record.
6. The method for generating field extraction paths based on webpage structure analysis according to claim 1, characterized in that, The process of determining the field extraction path by performing conflict folding on candidate field paths based on the coverage relationship between the hit node sets and the length of continuous segments in the path span record includes: Extract the set of hit nodes for multiple candidate field paths, compare the number of identical hit nodes and the number of different hit nodes among the sets of hit nodes, and generate a coverage relationship; Candidate field paths with more identical hit nodes than different hit nodes are grouped into the same path group based on coverage relationships. Extract the length of consecutive segments from the path span records within the path group, and set the candidate field path with the largest consecutive segment length as the group representative path. Sort the group representative path and non-group candidate field paths according to the number of hit nodes, remove candidate field paths whose hit node set is completely contained by the group representative path, and determine the remaining candidate field paths as field extraction paths.
7. The method for generating field extraction paths based on webpage structure analysis according to claim 1, characterized in that, The process of obtaining the source code of the target webpage includes: Receive the Uniform Resource Locator (URL) of the target webpage, send a Hypertext Transfer Protocol (HTTP) request according to the URL, and obtain the initial response content; Identify script reference markers and style reference markers in the initial response content, extract the script content corresponding to the script reference markers, and execute the script content according to the document object interface to obtain the executed document tree; The document tree after execution is associated with the style reference tags in the initial response content to generate the associated document tree; The associated document tree is serialized into the source code of the target webpage according to the tag hierarchy.
8. The method for generating field extraction paths based on webpage structure analysis according to claim 3, characterized in that, When the name matching fails, a virtual closed segment is generated at the position of the closed tag segment, and the virtual closed segment is attached to the nearest open tag segment in the stack structure, including: When a name match fails, read the tag name of the closed tag fragment and search for the open tag fragment with the same tag name from top to bottom in the stack structure; If an open tag segment with the same tag name is found, the open tag segment located above the found open tag segment in the stack structure is identified as the segment to be closed. Before the closing label segment position, virtual closing segments corresponding to the closing segments to be filled are generated in reverse order according to the push order of the closing segments to be filled in the stack structure; Attach the virtual closed segment corresponding to the closed segment to be filled to the closed segment to be filled, and pop the closed segment to be filled from the stack structure.
9. The method for generating field extraction paths based on webpage structure analysis according to claim 4, characterized in that, The step of converting the parent segment identifier, child segment identifier, previous neighbor segment identifier, and subsequent neighbor segment identifier in the repeating structure into node attribute tokens, hierarchical transfer tokens, and adjacent position tokens, respectively, includes: For the parent fragment identifier and child fragment identifier, read the tag name, identifier attribute value and class name attribute value of the corresponding node fragment, and concatenate them into a node attribute token in the order of tag name, identifier attribute value and class name attribute value; For the parent fragment identifier and child fragment identifier, read the level number of the corresponding node fragment, and concatenate them into a level transfer token in the order of parent fragment level number, child fragment level number, parent fragment tag name, and child fragment tag name; For the preceding and following segment identifiers, read the tag name and same-level sequence number of the corresponding node segment, and concatenate them into an adjacent position token in the order of preceding segment tag name, current segment tag name, following segment tag name, and same-level sequence number; Write the node attribute token, hierarchy transfer token, and adjacent position token into the candidate field path according to their positions in the candidate field path, following the repeating structure.
10. The method for generating field extraction paths based on webpage structure analysis according to claim 5, characterized in that, The records of hit consecutive segments and text offsets are used to obtain a set of hit nodes and a path span record, including: For two adjacent hit nodes in the hit node set, read the end offset and start offset of the two hit nodes in the node segment sequence; If the node segments between the end offset and the start offset are both blank segments, then the two hit nodes will be merged into the same hit contiguous segment. If there is a non-blank segment between the end offset and the start offset, or if the level numbers of the two hit nodes are different, then a new hit continuum is established between the two hit nodes. Write the start node offset, end node offset, text character start position, and text character end position of each hit continuous segment into the path span record, and set the segment number according to the order of the hit continuous segments in the node segment sequence.
