Webpage node topological relation prediction method and device, equipment and storage medium
By constructing a DOM tree and using pre-trained models, it automatically predicts the categories and topological relationships of web page nodes, solving the problems of low efficiency and insufficient accuracy of traditional methods, and achieving a more efficient and accurate understanding and analysis of web page structure.
Patent Information
- Application Number
- CN202410613550.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-16
- Publication Date
- 2024-08-27
AI Technical Summary
Traditional web page node topological relationship prediction methods are inefficient and difficult to guarantee accuracy, and cannot effectively handle complex web page structures.
By obtaining the HTML code and rendering information of the web page, a DOM tree is constructed, combined with the pre-trained prediction model, to automatically predict the categories and topological relationships of web page nodes, and then derive fine-grained topological relationships.
It improves the efficiency and accuracy of web page parsing, provides more detailed web page structure information, is suitable for tasks such as automatic web page navigation, automated testing, and information extraction, and significantly reduces manual intervention and error rates.
Smart Images

Figure CN118550532A
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a method, device, equipment and storage medium for predicting the topological relationship of web page nodes. Background Art
[0002] With the rapid development of the Internet, web pages, as an important carrier of information dissemination, have become increasingly complex in structure and diverse in functions. Various elements on a web page, such as text, images, links, etc., are interconnected through complex node topological relationships, forming the overall structure of the web page. Accurate understanding and prediction of the topological relationship of web page nodes is of great significance for the extraction, analysis, reconstruction of web page content, and the realization of more complex web applications.
[0003] Traditional methods for predicting the topological relationship of web page nodes mainly rely on manual analysis and annotation, that is, parsing the web page source code, extracting each element node, and determining the topological relationship between these nodes through manual judgment or preset rules. This method is not only inefficient and requires a lot of manpower, but also difficult to guarantee accuracy, because the structure of web pages is complex and changeable, and it is difficult to accurately describe all situations through simple rules.
[0004] Therefore, it is an urgent need for those skilled in the art to obtain a method that can automatically predict the topological relationship of nodes on a web page to improve the efficiency and accuracy of web page parsing. Summary of the invention
[0005] In view of the above problems, the present application provides a method for predicting the topological relationship of web page nodes, including the following contents:
[0006] In a first aspect, the present application provides a method for predicting a topological relationship of web page nodes, the method comprising:
[0007] Obtaining HTML code and webpage rendering information of a target webpage, wherein the target webpage includes a plurality of nodes;
[0008] Parsing the HTML code to obtain a DOM tree of the target web page, wherein the DOM tree is a tree representation of a web page node structure, including a hierarchical relationship between all nodes;
[0009] Obtaining a coarse-grained topological relationship between the plurality of nodes in the target web page based on the DOM tree and the web page rendering information;
[0010] Using a pre-trained prediction model to predict the category of each node in the target webpage based on the DOM tree to obtain the category of each node;
[0011] A fine-grained topological relationship between the multiple nodes in the target webpage is obtained based on the category of each node, the information of the node and the coarse-grained topological relationship.
[0012] Optionally, the webpage rendering information includes specific locations of webpage nodes and size information of webpage nodes; and obtaining the coarse-grained topological relationship between the multiple nodes in the target webpage based on the DOM tree and the webpage rendering information includes:
[0013] A coarse-grained topological relationship between the multiple nodes in the target web page is obtained based on the DOM tree and the specific positions of the web page nodes and the size information of the web page nodes.
[0014] Optionally, obtaining the coarse-grained topological relationship between the multiple nodes in the target web page based on the specific positions of the DOM tree and the web page nodes and the size information of the web page nodes includes:
[0015] Based on the position and size information of each node, calculate the distance and overlap with other nodes;
[0016] A threshold is set according to the distance and overlap, and adjacent or similar nodes are classified into the same group or the same level.
[0017] Optionally, before predicting the category of each node in the target webpage based on the DOM tree using the pre-trained prediction model, the method further includes:
[0018] Obtain web page data with node category annotations as a training set;
[0019] The prediction model is trained based on the training set and the supervised learning method to obtain a trained prediction model.
[0020] Optionally, obtaining the fine-grained topological relationship between the multiple nodes in the target webpage based on the category of each node, the information of the node and the coarse-grained topological relationship includes:
[0021] Obtaining nodes in the same group or the same level according to the coarse-grained topological relationship;
[0022] Obtaining the category of each node in the same group or the same level, wherein the category includes a description category and a function category. When the node is a description category, obtaining the corresponding description text; when the node is a function category, obtaining the corresponding node name;
[0023] Input the node category and the node xpath information into the pre-trained prediction model;
[0024] The pre-trained prediction model outputs fine-grained topological relationships between the multiple nodes in the target webpage.
[0025] In a second aspect, the present application provides a device for predicting a topological relationship of web page nodes, the device comprising:
[0026] An acquisition unit, used to acquire HTML code and webpage rendering information of a target webpage, wherein the target webpage includes a plurality of nodes;
[0027] A parsing unit, used to parse the HTML code to obtain a DOM tree of the target web page, wherein the DOM tree is a tree representation of a web page node structure, including a hierarchical relationship between all nodes;
[0028] A first generating unit, configured to obtain a coarse-grained topological relationship between the plurality of nodes in the target web page based on the DOM tree and the web page rendering information;
[0029] A category generating unit, configured to predict the category of each node in the target web page based on the DOM tree using a pre-trained prediction model to obtain the category of each node;
[0030] The second generating unit is configured to obtain the fine-grained topological relationship between the plurality of nodes in the target webpage based on the category of each node, the information of the node and the coarse-grained topological relationship.
[0031] Optionally, the webpage rendering information includes specific positions of webpage nodes and size information of webpage nodes; and the first generating unit is specifically configured to:
[0032] A coarse-grained topological relationship between the multiple nodes in the target web page is obtained based on the DOM tree and the specific positions of the web page nodes and the size information of the web page nodes.
[0033] Optionally, the first generating unit is specifically used for:
[0034] Based on the position and size information of each node, calculate the distance and overlap with other nodes;
[0035] A threshold is set according to the distance and overlap, and adjacent or similar nodes are classified into the same group or the same level.
[0036] Optionally, the device further comprises a model training unit, which is used to obtain web page data with node category annotations as a training set;
[0037] The prediction model is trained based on the training set and the supervised learning method to obtain a trained prediction model.
[0038] Optionally, the second generating unit is specifically used for:
[0039] Obtaining nodes in the same group or the same level according to the coarse-grained topological relationship;
[0040] Obtaining the category of each node in the same group or the same level, wherein the category includes a description category and a function category. When the node is a description category, obtaining the corresponding description text; when the node is a function category, obtaining the corresponding node name;
[0041] Input the node category and the node xpath information into the pre-trained prediction model;
[0042] The pre-trained prediction model outputs fine-grained topological relationships between the multiple nodes in the target webpage.
[0043] In a third aspect, the present application provides a device comprising a memory and a processor, wherein the memory is used to store instructions or codes, and the processor is used to execute the instructions or codes so that the device executes the web page node topological relationship prediction method introduced in any implementation of the first aspect.
[0044] In a fourth aspect, the present application provides a computer-readable storage medium, in which codes are stored. When the codes are executed, the device executing the codes implements the web page node topological relationship prediction method introduced in any implementation of the aforementioned first aspect.
[0045] The present application provides a method for predicting the topological relationship of web page nodes. By automatically obtaining the HTML code and web page rendering information of the target web page, and parsing and generating a DOM tree, the whole process does not require manual intervention, which greatly improves the processing efficiency and automation level. By combining the DOM tree and web page rendering information, the spatial layout and hierarchical relationship of web page nodes can be more comprehensively understood, so as to more accurately obtain the coarse-grained topological relationship between multiple nodes. The node category is then predicted using a pre-trained prediction model, which further improves the accuracy of the prediction. On the basis of obtaining the coarse-grained topological relationship, combined with the category, information and coarse-grained topological relationship of the node, a more refined and specific fine-grained topological relationship can be further derived. This helps to understand the structure of the web page more deeply and provide more accurate and detailed data support for subsequent web page navigation, automated testing, information extraction and other tasks. Since the method can accurately predict the topological relationship of web page nodes, it can be widely used in multiple fields such as automatic web page navigation, automated testing, web page information extraction, web page understanding, etc. In these application scenarios, the method can significantly improve work efficiency and accuracy, and reduce manual intervention and error rate. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the technical solutions in this embodiment or the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0047] Figure 1 A flowchart of a method for predicting a topological relationship of web page nodes provided in an embodiment of the present application;
[0048] Figure 2 A schematic diagram of a web page interface provided in an embodiment of the present application;
[0049] Figure 3 A schematic diagram of the structure of a device for predicting the topological relationship of web page nodes provided in an embodiment of the present application. DETAILED DESCRIPTION
[0050] In order to make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of this application. It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data need to comply with the relevant laws, regulations and standards of relevant countries and regions.
[0051] Figure 1 A flowchart of a method for predicting the topological relationship of web page nodes provided in an embodiment of the present application.
[0052] Combination Figure 1 As shown, the webpage node topology relationship prediction method provided by the embodiment of the present application may include:
[0053] S101: Obtain HTML code and webpage rendering information of a target webpage, wherein the target webpage includes a plurality of nodes.
[0054] The target web page is the web page for which the node topology relationship prediction is to be performed. The nodes in the web page can also become elements in the web page. Web page elements are the basic units that constitute the content of the web page, and nodes are the representation of these elements in the web page structure. Specifically, web page elements can be text, images, links, buttons, etc., which are defined and described by HTML (Hypertext Markup Language) tags. In an HTML document, each element is regarded as a node, and these nodes together constitute the node tree (DOM tree, i.e., Document Object Model Tree) of the web page.
[0055] Node topology relationship prediction refers to the prediction of the association relationship between nodes in a web page. Figure 2 A schematic diagram of a web page interface provided in an embodiment of the present application, in Figure 2 In the figure, the upper part is a visualization result of a web page. The figure contains text descriptions such as "full-text search" and "case name", as well as functional elements such as input boxes and drop-down boxes. If the relationship between text descriptions and functional elements can be predicted, it can enhance the understanding of web pages and realize more complex web applications. Figure 2 The lower middle part is the DOM tree. Visually, "Full Text Search" is the description of the input box on the right, but it is not the same leaf node in the DOM structure. The role of topological relationship prediction is to connect the two, and then we can get: "Full Text Search-Input Box". By analogy, all related nodes on the web page can be connected.
[0056] The web page rendering information includes the specific location of the web page node and the size information of the web page node. Web page rendering refers to the process of presenting the content on the web page to the user. First, the browser will parse files such as HTML / SVG / XHTML, CSS and JavaScript. Parsing HTML / SVG / XHTML will generate a DOM (Document Object Model) tree, and parsing CSS will generate a CSS rule tree. JavaScript scripts mainly operate the DOM tree and CSS Rule tree through the DOM API and CSSOM API. After the parsing is completed, the browser engine will construct the Rendering tree through the DOM tree and CSS Rule tree. Finally, the browser will call the API of the operating system Native GUI to draw and display the web page content on the screen.
[0057] The Document Object Model (DOM) is a tree-like structure representation of a web page, which describes the hierarchical relationship between the various elements on the web page (such as text, images, links, etc.); CSS, or Cascading Style Sheets, is a technology used to control the appearance and layout of elements on a web page, defining the color, size, position and other attributes of the elements.
[0058] The specific position of a web page node usually refers to the coordinate position of the element on the page. In HTML documents, elements are positioned and laid out using CSS (Cascading Style Sheets). These positions may be relative to their parent element, the entire document, or the viewport (i.e., the visible area of the browser window); the size information of a web page node refers to the width and height of the element itself. These dimensions are also defined using CSS and may be affected by a variety of factors, such as the element's borders, padding, content size, etc. The size information of an element can be used to determine the amount of space it occupies on the page.
[0059] S102: Parse the HTML code to obtain a DOM tree of the target web page. The DOM tree is a tree representation of a web page node structure, including a hierarchical relationship between all nodes.
[0060] HTML parsing: When a browser receives an HTML document, it begins parsing the HTML code from top to bottom. This process identifies HTML tags (such as , , etc.) and convert them into corresponding DOM nodes.
[0061] DOM node: Each HTML tag is represented as a node in the DOM tree. These nodes can be of various types, including element nodes (corresponding to HTML tags), text nodes (corresponding to text content between tags), and attribute nodes (corresponding to attributes of HTML tags).
[0062] Hierarchical relationship: The DOM tree is a tree structure in which each node can have child nodes. This hierarchical relationship reflects the structure of the HTML document. For example, a An element node can contain multiple child nodes, such as Element nodes, Element node or other Element node.
[0063] Building the DOM tree: As the HTML code is parsed, the browser gradually builds the DOM tree. First, it parses the root element of the HTML document (usually the tag), then parses its child elements (such as and), then parses the child elements of these child elements, and so on.
[0064] After parsing, the relationship between the nodes is obtained. For example, node 1 and node 2 belong to node 3. Professional term node 3 is the parent node of nodes 1 and 2, and nodes 1 and 2 are child nodes of node 3.
[0065] S103: Obtain a coarse-grained topological relationship between the multiple nodes in the target web page based on the DOM tree and the web page rendering information.
[0066] Traverse the DOM tree, starting from the root node, and visit the child nodes layer by layer. By traversing the DOM tree, you can get the parent-child relationship and sibling relationship between nodes. For example: Node 1 and Node 2 belong to Node 3, and Node 3 is the parent node of Node 1 and 2, and Node 1 and 2 are the child nodes of Node 3. Divide the nodes at the same level together, and the final coarse-grained topological relationship example is: {node 1, node 2}, {node 3, node 4, node 5},... Figure 2 In the figure, the topological relationship between the elements "full-text search", input box and drop-down box is predicted to be: {node 3, node 4, node 5}, where node 3 corresponds to full-text search, node 4 corresponds to the input box, and node 5 corresponds to the full-text drop-down box.
[0067] A coarse-grained topological relationship between the multiple nodes in the target web page is obtained based on the DOM tree and the specific positions of the web page nodes and the size information of the web page nodes.
[0068] The specific positions of nodes can help determine the relative relationships between them, especially when the DOM tree structure is not sufficient to fully describe these relationships. For example, two nodes may be siblings in the DOM tree, but their actual layout on the page may indicate that one of the nodes is a sub-region or internal component of the other node; in addition, the size and position information of the nodes provides an intuitive understanding of the page layout. This information can help identify different areas on the page (such as headers, footers, sidebars, content areas, etc.), thereby determining the position of the node in the overall page structure. That is, obtaining coarse-grained topological relationships based on the DOM tree and the specific position and size information of web page nodes can provide a more comprehensive, accurate and useful description of the web page structure. This information helps to better understand the layout, structure and user interaction methods of the page, thereby supporting various web page analysis and application tasks.
[0069] In an implementation method of an embodiment of the present application, the coarse-grained topological relationship between the multiple nodes in the target web page is obtained based on the specific positions of the DOM tree and the web page nodes and the size information of the web page nodes, including: calculating the distance and overlap with other nodes based on the position and size information of each node; setting a threshold based on the distance and overlap, and classifying adjacent or similar nodes into the same group or the same level.
[0070] Specifically, the DOM tree is traversed first to obtain the precise position and size information of each node on the page, and then the distance between the nodes is calculated, such as the Euclidean distance (if the node position and size information is given in pixels), or other forms of distance measurement, such as Manhattan distance or chessboard distance, depending on the application scenario and requirements. Then, each pair of nodes is checked for overlap by comparing the bounding boxes of the nodes. If the bounding boxes of the two nodes intersect, there is overlap. The overlap can be the ratio of the area of the overlapping part to the area of the smaller of the two nodes. Based on the distance and overlap of the nodes, appropriate thresholds are set to determine which nodes should be classified into the same group or the same level. These thresholds are set in advance based on experimental or test results. According to the set thresholds, the nodes are classified into different groups or levels. If the distance between the two nodes is less than the distance threshold, or the overlap is greater than the overlap threshold, they can be classified into the same group or the same level.
[0071] S104: using a pre-trained prediction model to predict the category of each node in the target webpage based on the DOM tree to obtain the category of each node.
[0072] The pre-trained model can be a traditional discriminant model or a generative large model. The categories of the nodes can include: buttons, input boxes, drop-down boxes, description texts, etc. The descriptive text refers to the text description on the web page, which is usually used to identify and explain the elements or content on the web page. For example, the text on a button can be regarded as descriptive text.
[0073] In an implementation method of an embodiment of the present application, before predicting the category of each node in the target web page based on the DOM tree using a pre-trained prediction model, the method further includes:
[0074] Obtain web page data with node category annotations as a training set; train a prediction model based on the training set and a supervised learning method to obtain a trained prediction model.
[0075] In the process of obtaining web page data with node category annotations as training sets and using supervised learning methods to train prediction models, you can choose from a variety of models, including traditional discriminant models (such as support vector machines, random forests, logistic regression, etc.) and modern generative large models (such as BERT, GPT, etc.). The following is a simple implementation process using the BERT (Bidirectional Encoder Representations from Transformers) model as a generative large model:
[0076] 1. Data preparation
[0077] Data collection: Use web crawler tools (such as Scrapy, Selenium, etc.) to crawl web page data from the Internet.
[0078] Data cleaning: remove irrelevant information such as HTML tags, non-text content, and advertisements, and only retain the main content and structural information of the web page.
[0079] Node labeling: manually or using semi-automatic tools to label each node (such as paragraphs, titles, list items, etc.) on a web page.
[0080] Construct a training set: Divide the labeled web page data into a training set, a validation set, and a test set.
[0081] 2. Data Preprocessing
[0082] Text processing: perform word segmentation, stop word removal, stemming, and other processing on web page text.
[0083] Feature extraction: Convert the text into an input format that the BERT model can process, i.e. token IDs, segment IDs, attention masks, etc.
[0084] Node structure information: Encode the structural information of the node (such as parent-child relationship, sibling relationship, etc.) as features that the model can process.
[0085] 3. Model selection
[0086] BERT model: Select a pre-trained BERT model as the base model. BERT is a Transformer-based bidirectional encoder with powerful text representation capabilities.
[0087] 4. Model Training
[0088] Load pre-trained model: Load the pre-trained BERT model weights.
[0089] Define task-specific layers: Based on the BERT model, add one or more task-specific layers (such as fully connected layers) for classification tasks.
[0090] Set the loss function and optimizer: Choose a loss function (such as cross entropy loss) and optimizer (such as Adam) suitable for the classification task.
[0091] Training model: Use the training set data to train the model and update the model parameters through back propagation and gradient descent.
[0092] Validate model: After each training cycle, use the validation set to evaluate the performance of the model and save the best model.
[0093] S105. Obtain the fine-grained topological relationship between the multiple nodes in the target web page based on the categories of the nodes, the information of the nodes, and the coarse-grained topological relationship.
[0094] Compared with the coarse-grained topological relationship, the fine-grained topological relationship can display the relationship between nodes more clearly. The specific process of obtaining the fine-grained topological relationship includes: obtaining the nodes in the same group or the same level according to the coarse-grained topological relationship; obtaining the categories of the nodes in the same group or the same level, where the categories include descriptive classes and functional classes. When the node is a descriptive class, obtain the corresponding descriptive text; when the node is a functional class, obtain the corresponding node name; input the category of the node and the xpath path information of the node into the pre-trained prediction model; the pre-trained prediction model outputs the fine-grained topological relationship between the multiple nodes in the target web page.
[0095] Xpath can be used to represent the storage path of a specific node on a web page. For example, the storage path in a computer refers to the path to find files or folders on the computer, such as:
[0096] C:\Users\YourUsername\Documents\Pictures\照片.jpg; The Xpath of a certain node in the embodiment of the present application can be expressed as: / html / body / div[2] / a[1] / span.
[0097] In step S103, {node 3, node 4, node 5} are divided into the same level. Before obtaining the fine-grained topological relationship, first determine that node 3, node 4, and node 5 are in the same level, and then respectively judge their corresponding types. For example, the types of node 3-5 are descriptive text, input box, and dropdown box respectively. Then obtain the xpath path information of each node. Finally, the result output by the model is: full text search - input box, full text - dropdown box, that is, the fine-grained topological relationship of the nodes.
[0098] The web page node topological relationship prediction method provided in the above embodiments of the present application can automatically predict and identify the topological relationship of web page elements. In addition, the present application can not only be used for automatic web page navigation and automated testing, but also play an important role in multiple fields such as web page information extraction and web page understanding, thereby improving work efficiency and accuracy.
[0099] The above are some specific implementation manners of a web page node topological relationship prediction method provided in the embodiments of the present application. Based on this, the present application also provides a corresponding device. The device provided in the embodiments of the present application will be introduced from the perspective of functional modularization below.
[0100] Figure 3 A schematic diagram of a device for predicting topological relationships of web page nodes provided in an embodiment of the present application. Figure 3 As shown, the webpage node topology relationship prediction device 300 provided in the embodiment of the present application includes:
[0101] The acquisition unit 310 is used to acquire the HTML code and webpage rendering information of the target webpage, wherein the target webpage includes a plurality of nodes;
[0102] A parsing unit 320 is used to parse the HTML code to obtain a DOM tree of the target web page, where the DOM tree is a tree representation of a web page node structure, including a hierarchical relationship between all nodes;
[0103] A first generating unit 330 is configured to obtain a coarse-grained topological relationship between the multiple nodes in the target web page based on the DOM tree and the web page rendering information;
[0104] A category generating unit 340 is used to predict the category of each node in the target webpage based on the DOM tree using a pre-trained prediction model to obtain the category of each node;
[0105] The second generating unit 350 is configured to obtain a fine-grained topological relationship between the plurality of nodes in the target webpage based on the category of each node, the information of the node and the coarse-grained topological relationship.
[0106] In an implementation method of an embodiment of the present application, the webpage rendering information includes specific positions of webpage nodes and size information of webpage nodes; the first generating unit is specifically used to:
[0107] A coarse-grained topological relationship between the multiple nodes in the target web page is obtained based on the DOM tree and the specific positions of the web page nodes and the size information of the web page nodes.
[0108] In an implementation method of an embodiment of the present application, the first generating unit is specifically used to:
[0109] Based on the position and size information of each node, calculate the distance and overlap with other nodes;
[0110] A threshold is set according to the distance and overlap, and adjacent or similar nodes are classified into the same group or the same level.
[0111] In an implementation method of an embodiment of the present application, the device further includes a model training unit, which is used to obtain web page data with node category annotations as a training set;
[0112] The prediction model is trained based on the training set and the supervised learning method to obtain a trained prediction model.
[0113] In an implementation method of an embodiment of the present application, the second generating unit is specifically used to:
[0114] Obtaining nodes in the same group or the same level according to the coarse-grained topological relationship;
[0115] Obtaining the category of each node in the same group or the same level, wherein the category includes a description category and a function category. When the node is a description category, obtaining the corresponding description text; when the node is a function category, obtaining the corresponding node name;
[0116] Input the node category and the node xpath information into the pre-trained prediction model;
[0117] The pre-trained prediction model outputs fine-grained topological relationships between the multiple nodes in the target webpage.
[0118] The embodiments of the present application also provide corresponding devices and computer storage media for implementing the solutions provided by the embodiments of the present application.
[0119] The device includes a memory and a processor, the memory is used to store instructions or codes, and the processor is used to execute the instructions or codes so that the device executes the method described in any embodiment of the present application.
[0120] The computer storage medium stores codes, and when the codes are executed, a device executing the codes implements the method described in any embodiment of the present application.
[0121] Through the description of the above implementation methods, it can be known that those skilled in the art can clearly understand that all or part of the steps in the above-mentioned embodiment method can be implemented by means of software plus a general hardware platform. Based on such an understanding, the technical solution of the present application can be embodied in the form of a software product, which can be stored in a storage medium, such as a read-only memory (ROM) / RAM, a magnetic disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network communication device such as a router) to execute the methods described in each embodiment of the present application or some parts of the embodiments.
[0122] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.
[0123] It should also be noted that the various embodiments in this specification are described in a progressive manner, and the same and similar parts between the various embodiments can refer to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device and apparatus embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can refer to the partial description of the method embodiments. The device and apparatus embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components indicated as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0124] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A method for predicting topological relationships of web page nodes. It is characterized in that The method comprises: Obtaining HTML code and webpage rendering information of a target webpage, wherein the target webpage includes a plurality of nodes; Parsing the HTML code to obtain a DOM tree of the target web page, wherein the DOM tree is a tree representation of a web page node structure, including a hierarchical relationship between all nodes; Obtaining a coarse-grained topological relationship between the plurality of nodes in the target web page based on the DOM tree and the web page rendering information; Using a pre-trained prediction model to predict the category of each node in the target webpage based on the DOM tree to obtain the category of each node; A fine-grained topological relationship between the multiple nodes in the target webpage is obtained based on the category of each node, the information of the node and the coarse-grained topological relationship.
2. The method according to claim 1, It is characterized in that The webpage rendering information includes the specific location of the webpage node and the size information of the webpage node; the coarse-grained topological relationship between the multiple nodes in the target webpage obtained based on the DOM tree and the webpage rendering information includes: A coarse-grained topological relationship between the multiple nodes in the target web page is obtained based on the DOM tree and the specific positions of the web page nodes and the size information of the web page nodes.
3. The method according to claim 2, It is characterized in that The obtaining of the coarse-grained topological relationship between the plurality of nodes in the target web page based on the specific positions of the DOM tree and the web page nodes and the size information of the web page nodes comprises: Based on the position and size information of each node, calculate the distance and overlap with other nodes; A threshold is set according to the distance and overlap, and adjacent or similar nodes are classified into the same group or the same level.
4. The method according to claim 1, It is characterized in that Before predicting the category of each node in the target webpage based on the DOM tree using the pre-trained prediction model, the method further includes: Obtain web page data with node category annotations as a training set; The prediction model is trained based on the training set and the supervised learning method to obtain a trained prediction model.
5. The method according to claim 1, It is characterized in that The obtaining of the fine-grained topological relationship between the plurality of nodes in the target webpage based on the category of each node, the information of the node and the coarse-grained topological relationship includes: Obtaining nodes in the same group or the same level according to the coarse-grained topological relationship; Obtaining the category of each node in the same group or the same level, wherein the category includes a description category and a function category. When the node is a description category, obtaining the corresponding description text; when the node is a function category, obtaining the corresponding node name; Input the node category and the node xpath information into the pre-trained prediction model; The pre-trained prediction model outputs fine-grained topological relationships between the multiple nodes in the target webpage.
6. A device for predicting topological relationships of web page nodes, It is characterized in that The device comprises: An acquisition unit, used to acquire HTML code and webpage rendering information of a target webpage, wherein the target webpage includes a plurality of nodes; A parsing unit, used to parse the HTML code to obtain a DOM tree of the target web page, wherein the DOM tree is a tree representation of a web page node structure, including a hierarchical relationship between all nodes; A first generating unit, configured to obtain a coarse-grained topological relationship between the plurality of nodes in the target web page based on the DOM tree and the web page rendering information; A category generating unit, configured to predict the category of each node in the target web page based on the DOM tree using a pre-trained prediction model to obtain the category of each node; The second generating unit is configured to obtain the fine-grained topological relationship between the plurality of nodes in the target webpage based on the category of each node, the information of the node and the coarse-grained topological relationship.
7. The device according to claim 6, It is characterized in that The webpage rendering information includes the specific location of the webpage node and the size information of the webpage node; the first generating unit is specifically used for: A coarse-grained topological relationship between the multiple nodes in the target web page is obtained based on the DOM tree and the specific positions of the web page nodes and the size information of the web page nodes.
8. The device according to claim 7, It is characterized in that The first generating unit is specifically used for: Based on the position and size information of each node, calculate the distance and overlap with other nodes; A threshold is set according to the distance and overlap, and adjacent or similar nodes are classified into the same group or the same level.
9. A computing device, It is characterized in that The computing device includes: a memory and a processor; The memory is used to store computer programs; The processor is configured to implement the method according to any one of claims 1 to 5 when executing the computer program.
10. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.
