Webpage list page link identification method
Converting the Dom tree through xpath and using the cosine similarity algorithm solves the problem of difficulty in identifying list pages using traditional methods, and achieves efficient, accurate identification and accurate extraction of web page links.
Patent Information
- Application Number
- CN202410779240.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-17
- Publication Date
- 2024-10-18
AI Technical Summary
Traditional web page parsing methods are difficult to accurately identify list pages, affecting the efficiency of information extraction and processing.
Preprocess the web page list, use .
It achieves efficient and accurate identification of links on different web page list pages, and improves the accuracy and adaptability of identification.
Smart Images

Figure CN118797193A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of web page link identification, and in particular to a web page list page link identification method. Background Art
[0002] With the rapid development of Internet technology, it has become a normal practice for users to obtain information through web browsing. Among many web pages, list pages, with their structured information display form, provide users with the convenience of fast retrieval and browsing. However, due to the diversity and complexity of web page design, traditional web page parsing methods are difficult to accurately identify list pages, which affects the efficiency of information extraction and processing. Summary of the invention
[0003] In view of this, the problem to be solved by the present invention is to provide a method for identifying a link in a web page list.
[0004] In order to solve the above technical problems, the technical solution adopted by the present invention is:
[0005] A method for identifying a page link in a web page list comprises: step 1, preprocessing a web page list, obtaining an HTML document of the web page list, and converting the HTML document into a DOM tree through XPath;
[0006] Step 2: filtering links. The DOM tree includes several entities. Starting from the root of the DOM tree, the entities are traversed to filter the link URLs containing preset tags in the entities, extract and form a link group.
[0007] Step 3: extract links, combine the link URLs in the link group in pairs, convert them into vector arrays according to the type and number of strings contained in the link URLs, use the cosine similarity theorem to calculate the similarity of the two vector arrays, and judge whether the two link URLs are similar based on whether the similarity exceeds a threshold. The link URLs with high similarity are retained in the link group;
[0008] Step 4: Output links, filter link URLs based on keywords, and output links that meet the rules.
[0009] Furthermore, the HTML is an embedded code with a format identifier and a hypertext link. After obtaining the HTML document of the web page list in step 1, irrelevant tags in the HTML document are deleted.
[0010] Furthermore, the irrelevant tags include script tags, style tags or img tags.
[0011] Furthermore, the link group generation process in step 2 includes: determining whether there is text content under the preset tag, if yes, recording the text content and removing duplicates, and storing it in the link group in the link url format, if no, continuing to traverse.
[0012] Furthermore, the preset tag includes an h tag, a ul / li tag, a tr / td tag or an article tag.
[0013] Furthermore, the method for generating the vector array in step 3 is: obtaining the character string in the link URL with the slash as the interval, removing the symbols in the character string to generate a single link set, and recording the number of occurrences in sequence according to the arrangement order of the character string in the single link set to form an array of the link URL;
[0014] The union of two single link sets generates a double link set, and the double link set is compared with the two single link sets respectively to determine the number and position of different strings in the double link set and the single link set, and the corresponding number of 0s are added to the corresponding positions in the array to generate a vector array of the link url.
[0015] Furthermore, the cosine similarity theorem in step 3 includes the cosine similarity formula:
[0016]
[0017] Where cos(A,B) represents the similarity between link A and link B, S represents the dot product of the corresponding vector arrays of link A and link B, ‖A‖ represents the vector value of the vector array of link A, and ‖B‖ represents the vector value of the vector array of link B.
[0018] The advantages and positive effects of the present invention are:
[0019] By deleting irrelevant tags in HTML documents and converting HTML documents into Dom trees, and extracting connections within the same web page list page through XPath and Dom trees, efficient and accurate identification of links between different web page list pages can be achieved.
[0020] Through xpath, link urls that meet the requirements are extracted to generate link groups. Any two link urls in the link group are combined and converted into vector arrays. The similarity of two link urls is calculated based on the cosine similarity theorem and vector arrays. Link urls can be screened and non-link information in the link group can be further removed. The cosine similarity algorithm is used to further screen the link urls extracted by xpath, which improves the accuracy and adaptability of recognition. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:
[0022] Figure 1 It is an overall flow chart of a web page list page link identification method of the present invention;
[0023] Figure 2 It is a flow chart of identifying a connection group of a web page list page link identification method of the present invention. DETAILED DESCRIPTION
[0024] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0025] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used herein in the specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. The term "and / or" used herein includes any and all combinations of one or more related listed items.
[0026] HTML documents are descriptive texts composed of HTML commands. HTML commands can describe text, graphics, animations, sounds, tables, links, etc. The HTML web page structure consists of two parts: the head and the body. The head describes the information required by the browser, and the body contains the specific link content to be described.
[0027] Xpath, or XML Path Language, is used to search HTML documents and extract information. The Dom tree includes a node tree: all the content in the document is considered as a tree, and each body in the HTML document is a node of the Dom tree. The link url is in a fixed format, consisting of "protocol: / / host name:port number / path?query string".
[0028] The present invention provides a web page list link identification method, such as Figure 1 and Figure 2 As shown, it includes step 1, preprocessing the web page list, obtaining the HTML document of the web page list, and converting the HTML document into a Dom tree through xpath.
[0029] The html document includes several link information. Since links have specific format requirements, use xpath to search the html file, determine all the links in the html document, and generate a Dom tree to facilitate quick search of the corresponding link information in the html document based on the Dom tree.
[0030] When users generate HTML documents with their own devices, the link information contains the user's device information and access information tags. When the same link accesses different servers, the generated link tags are not exactly the same. This results in the same link information containing different tags. To improve the accuracy of link recognition, after obtaining the HTML document of the web page list, use XPath to search and delete irrelevant tags, remove redundant tags in the link, and improve the accuracy of XPath link extraction.
[0031] An embodiment of the present application is that the irrelevant tags include script tags, style tags or img tags.
[0032] Step 2: filter links. The DOM tree includes several entities. Starting from the root of the DOM tree, the entities are traversed to filter link URLs containing preset tags in the entities, extract and form a link group.
[0033] After the html document generates the Dom tree, it traverses the body starting from the root of the Dom tree and filters the body according to the xpath rule to determine whether the body contains preset tags. If it contains preset tags, it determines whether the preset tags contain text content. If yes, it means that the preset tags contain text content that records link information. During the link access process, due to usage requirements or access reasons, there are repeated access processes, resulting in link information containing repeated tags. The tags in the text content are deduplicated and then stored in the link group in the link url format. The link url is a fixed format, which consists of "protocol: / / host name:port number / path?query string".
[0034] No, it means that the preset tag does not contain text content recording link information, and you can continue to traverse other bodies on the Dom tree. After traversing all bodies on the Dom tree, you can store the link URLs of all preset tags recorded in the HTML document into the array.
[0035] An embodiment of the present application is: the preset tag is an a tag, and the a tag includes an h tag, a ul / li tag, a tr / td tag or an article tag.
[0036] Step 3: extract links, combine the link URLs in the link group in pairs, convert them into vector arrays based on the type and number of strings contained in the link URLs, use the cosine similarity theorem to calculate the similarity of the two vector arrays, and determine whether the two link URLs are similar based on whether the similarity exceeds a threshold. Link URLs with high similarity are retained in the link group.
[0037] Combine any two of the link URLs in the link group, calculate the similarity of the link URLs in the combination, and determine whether the two link URLs are similar based on the similarity. If the similarity exceeds the threshold, it means that both are real link information and they are retained in the link group. If the similarity of the two is lower than the threshold, it means that at least one of them is not link information and they are not retained. This can further filter the links in the link group, making it convenient to filter the required links in the link group based on feature words later.
[0038] Because the format of the link URL is fixed, the link URL is divided into several strings separated by slashes, and other symbols except letters in the string are removed to generate a single link set.
[0039] According to the order of the string in the link URL, the number of occurrences of the string is recorded in sequence to generate an array of the link URL.
[0040] The union of two single-link sets generates a double-link set, which contains all the strings in the two single-link sets. The double-link set is compared with the two single-link sets to determine the number and position of different strings in the double-link set and the single-link set, and the corresponding number of 0s is added to the corresponding positions in the array to generate a vector array of the link url.
[0041] An embodiment of the present application is: two link URLs are: https: / / a.com / news / article? and https: / / a.com / news / video?. After processing, the single link sets of the two link URLs are obtained: A: [('https'), ('acom'), ('news'), ('article')] and B: [('https'), ('acom'), ('news'), ('video')], and the arrays generated by the two link URLs are: [1,1,1,1,], [1,1,1,1].
[0042] Since the tags in the link URL are deduplicated, theoretically the number of each string is 1. If the number of strings is not 1, the array only records the number of strings once, and the record is the first occurrence position.
[0043] The corresponding dual-link set is: [('https'),('acom'),('news'),('article'),('article')]. The dual-link set is compared with the first single-link set, and the generated vector array A is: [1,1,1,1,0]. The dual-link set is compared with the second single-link set, and the generated vector array B is: [1,1,1,0,1].
[0044] The cosine similarity formula is used to calculate the similarity of two single-link sets. The formula is as follows:
[0045]
[0046] Where cos(A,B) represents the similarity between link A and link B, S represents the dot product of the corresponding vector arrays of link A and link B, ‖A‖ represents the vector value of the vector array of link A, and ‖B‖ represents the vector value of the vector array of link B.
[0047] S is calculated by multiplying the elements in the two word vector arrays and then taking the sum. ‖A‖ and ‖B‖ are calculated by raising the elements in the two word vector arrays to the power of 2 and then adding them and taking the square root.
[0048] An embodiment of the present application is: S=1×1+1×1+1×1+1×0+0×1=3, Therefore, cos(A,B) is 0.75. If the similarity of the two link URLs calculated by the formula exceeds 0.7, it is considered that A and B are indeed link information, and these two link URLs are retained in the link group. If the similarity is lower than 0.7, it is considered that at least one of A and B is not link information, and A and B are not retained until it is determined that there is a combination of similarities in the link group, and the link URLs in the link group that are not links are filtered out.
[0049] Step 4: Output links, filter link URLs based on keywords, and output links that meet the rules.
[0050] When a user searches for a link, he or she provides a keyword or a key string. Based on the keyword or key string, several corresponding related link URLs are screened out in the link group, and the link URLs that meet the rules are output.
[0051] The present invention is characterized in that:
[0052] Remove redundant tags in HTML documents, and convert HTML documents into Dom tree form through XPath. When users search for links later, they can quickly traverse the main body of HTML documents containing link information, extract link URLs containing the required a tags and store them in link groups, combine link URLs in link groups in pairs, and convert them into vector arrays. Calculate the similarity of the two vector arrays through the cosine similarity theorem, retain link URL combinations with high structural similarity in the link group, and further remove non-link information in the link group. Quickly output links that meet the rules through keywords or key characters provided by users.
[0053] The organic combination of data preprocessing, feature screening, link extraction and result output steps realizes the efficient and accurate recognition of links in different web page lists; at the same time, the cosine similarity algorithm is used to optimize link recognition, further improving the accuracy and adaptability of recognition.
[0054] The embodiments of the present invention are described in detail above, but the contents described are only preferred embodiments of the present invention and cannot be considered to limit the scope of implementation of the present invention. All equivalent changes and improvements made within the scope of the present invention should still fall within the scope of this patent.
Claims
1. A method for identifying links in a web page list, characterized in that: include, Step 1: pre-process the web page list, obtain the HTML document of the web page list, and convert the HTML document into a Dom tree through XPath; Step 2: filtering links. The DOM tree includes several entities. Starting from the root of the DOM tree, the entities are traversed to filter the link URLs containing preset tags in the entities, extract and form a link group. Step 3: extract links, combine the link URLs in the link group in pairs, convert them into vector arrays according to the type and number of strings contained in the link URLs, use the cosine similarity theorem to calculate the similarity of the two vector arrays, and judge whether the two link URLs are similar based on whether the similarity exceeds a threshold. The link URLs with high similarity are retained in the link group; Step 4: Output links, filter link URLs based on keywords, and output links that meet the rules.
2. A web page list link identification method according to claim 1, characterized in that: The html is an embedded code with a format identifier and a hypertext link. After obtaining the html document of the web page list in step 1, irrelevant tags in the html document are deleted.
3. A web page list link identification method according to claim 2, characterized in that: The irrelevant tags include script tags, style tags or img tags.
4. A web page list page link identification method according to claim 1, characterized in that: The process of generating the link group in step 2 includes: determining whether there is text content under the preset tag, if yes, recording the text content and removing duplicates, and storing it in the link group in the link URL format, if no, continuing to traverse.
5. A web page list link identification method according to claim 1, characterized in that: The preset tags include h tags, ul / li tags, tr / td tags or article tags.
6. A web page list page link identification method according to claim 1, characterized in that: The method for generating the inner vector array in step 3 is as follows: obtaining the character string in the link URL with the slash as the interval, removing the symbols in the character string to generate a single link set, and recording the number of occurrences in sequence according to the arrangement order of the character string in the single link set to form an array of the link URL; The union of two single link sets generates a double link set, and the double link set is compared with the two single link sets respectively to determine the number and position of different strings in the double link set and the single link set, and the corresponding number of 0s are added to the corresponding positions in the array to generate a vector array of the link url.
7. A web page list link identification method according to claim 6, characterized in that: The cosine similarity theorem of step 3 includes the cosine similarity formula: Where cos(A,B) represents the similarity between link A and link B, S represents the dot product of the corresponding vector arrays of link A and link B, ‖A‖ represents the vector value of the vector array of link A, and ‖B‖ represents the vector value of the vector array of link B.
Citation Information
Patent Citations
Method and system for extracting news record metadata from news list page
CN102467501A
Word vector model-based micro-service interface division evaluation method
CN113760778A
Unsupervised detection of web pages corresponding to a similarity class
US20090157607A1
