Method and device for determining real height of webpage, equipment and medium

By using the breadth priority algorithm in web page forensics, the true height of the web page is calculated, which solves the problem that the true height of the complex web page cannot be accurately obtained in the existing technology, and ensures long screenshots and scrolling data extraction Integrity.

CN118885685APending Publication Date: 2024-11-01SHANGHAI HONGLIAN NETWORK CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410921241.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-10
Publication Date
2024-11-01

AI Technical Summary

Technical Problem

It is difficult to accurately calculate the true height of third-party web pages, especially in web pages containing CSS Overflow properties or nested web pages. The true height of complex web pages cannot be obtained, resulting in incomplete long screenshots or incomplete scrolling extraction data.

Method used

The preset breadth priority algorithm is used to find the minimum element in the center of the target web page containing the document layer by layer, and identify the maximum overflow height element. By obtaining the maximum overflow height and the original page height, the true height of the web page is calculated.

Benefits of technology

Through traversal, the maximum overflow height element is found, and the true height of the web page is calculated, solving the problem of incomplete long screenshots or incomplete scroll extraction data caused by the lack of real height in web page forensics.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118885685A_ABST
    Figure CN118885685A_ABST
Patent Text Reader

Abstract

The invention provides a method, a device and equipment for determining the real height of a webpage and a medium, and the method comprises the following steps: based on a preset breadth-first algorithm, finding out a minimum element of a target webpage containing a document center position layer by layer; based on the minimum element, identifying a maximum overflow height element in the target webpage; and obtaining the maximum overflow height of the maximum overflow height element and the original page height of the target webpage, and determining the real height of the target webpage according to the maximum overflow height and the original page height. According to the webpage HTML standard, the maximum overflow height element is found out in a traversal mode, then the actual height of the webpage is calculated by adding the original webpage height to the overflow height of the maximum overflow height element, and the problems that in the current webpage evidence obtaining field, due to lack of the actual height of the webpage, long screenshots are incomplete, and the real height of the webpage is not complete are solved. Or webpage data rolling extraction is incomplete.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of web page forensics, and in particular to a method, device, equipment and medium for determining the true height of a web page. Background Art

[0002] Web page screenshots are an important part of web page forensics, ensuring the integrity and non-tamperability of web page content. <iframe>When you want to take a screenshot of a webpage (element) or scroll a third-party webpage to extract data on the webpage, you need to determine the real height of the webpage in advance. The real height of the webpage refers to the total height of the webpage content, including all visible and invisible (need to scroll to see) parts. At present , the difficulty of calculating the real height of a web page is that web page evidence collection is for a third-party web page, and the implementation logic of the third-party web page cannot be known, and the methods for publicly obtaining the height of a web page provided by a front-end programming language or a browser are relatively limited, and there is no method for calculating the height of overflow of internal elements of a web page. For internal use of CSS Overflow attribute scroll bars or web pages containing Iframe (Framest) and nesting, existing methods cannot obtain the real height of the above-mentioned complex web pages. Therefore, it is urgent to solve the above problem by a method that can obtain the real height of a web page for various types of web pages. Summary of the invention

[0004] In view of the above problems, the present invention is proposed to provide a method, device, equipment and medium for determining the true height of a web page that overcomes the above problems or at least partially solves the above problems.

[0005] To achieve the above-mentioned object and other related objects, the present invention provides a method for determining the true height of a web page, the method comprising:

[0006] Based on a preset breadth-first algorithm, the minimum element of the target webpage containing the center position of the document is found layer by layer; wherein the minimum element is the most basic HTML element located at the center position of the document in the target webpage;

[0007] Based on the minimum element, identifying the element with the maximum overflow height in the target webpage; wherein the maximum overflow height is the element in the target webpage whose element content exceeds the height limit of its container, resulting in the appearance of a vertical scroll bar;

[0008] The maximum overflow height of the maximum overflow height element and the original page height of the target web page are obtained, and the real height of the target web page is determined according to the maximum overflow height and the original page height.

[0009] Optionally, the method of searching layer by layer for the minimum element of the target web page containing the center position of the document based on a preset breadth-first algorithm includes:

[0010] Create an element queue, add the root node of the target web page to the element queue, and add all child nodes of the root node to the element queue; <b

[0011] For each element in the element queue, determine whether the coordinates of the element contain the center position of the document;

[0012] When it is detected that the coordinates of the element include the center position of the document, detecting whether the element has a child node;

[0013] When it is detected that the element does not have a child node, the element is determined to be the smallest element of the target web page that contains the center position of the document.

[0014] Optionally, after the step of determining, for each element in the element queue, whether the coordinates of the element include the center position of the document, the step further includes:

[0015] When it is detected that the coordinates of the element do not include the center position of the document, all child nodes of the element are added to the element queue;

[0016] The step of determining whether the coordinates of each element in the element queue contain the center position of the document is executed in a loop until the element queue is empty, and the traversal is terminated.

[0017] Optionally, the step of identifying the element with the maximum overflow height in the target webpage based on the minimum element includes:

[0018] Determine whether the minimum element is a nested element;

[0019] If the minimum element is a nested element, the minimum element is determined as the element with the maximum overflow height in the target web page;

[0020] Conversely, if the minimum element is not a nested element, determining whether the minimum element is an overflow element;

[0021] If the minimum element is an overflow element, and when it is detected that there is no record of an overflow height element, record the minimum element as the maximum overflow height element;

[0022] On the contrary, if the minimum element is not an overflow element, the parent element of the minimum element is taken, and when the parent element is not empty, the parent element is set as the minimum element, and the step of determining whether the minimum element is a nested element is executed repeatedly until the element with the maximum overflow height in the target web page is identified, and the traversal is terminated.

[0023] Optionally, obtaining the maximum overflow height of the maximum overflow height element and the original page height of the target webpage, and determining the real height of the target webpage according to the maximum overflow height and the original page height, includes: <b

[0024] When it is determined that the maximum overflow height element is an overflow element, obtaining the viewport height and the scroll height of the maximum overflow height element and obtaining the original page height of the target web page;

[0025] Determining a maximum overflow height according to a difference between the scroll height and the viewport height;

[0026] The actual height of the target web page is determined based on the sum of the original web page height and the maximum overflow height.

[0027] Optionally, obtaining the maximum overflow height of the maximum overflow height element and the original page height of the target webpage, and determining the real height of the target webpage according to the maximum overflow height and the original page height, includes:

[0028] When the element with the maximum overflow height is a nested element, enter the internal content of the nested element and continue traversing, set the internal content of the nested element as the target webpage, and cyclically execute the steps of searching layer by layer for the minimum element containing the center position of the document on the target webpage based on a preset breadth-first algorithm to the step of determining the type of the element with the maximum overflow height, until the element with the maximum overflow height of the internal content is identified, and the traversal is terminated;

[0029] determining whether the maximum overflow height element of the internal content is an overflow element, and if the maximum overflow height element is an overflow element, obtaining the viewport height and the scroll height of the maximum overflow height element and obtaining the original page height of the target webpage;

[0030] According to the difference between the scroll height and the viewport height, a maximum overflow height is determined, and according to the sum of the original web page height and the maximum overflow height, a real height of the target web page is determined.

[0031] Optionally, after the step of finding the minimum element of the target webpage containing the center position of the document, the method further comprises:

[0032] Based on the minimum element, identifying that there is no maximum height overflow element in the target webpage;

[0033] Obtain the original page height of the target webpage, and determine the original page height as the real height of the target webpage.

[0034] In a second aspect, the present invention further provides a device for determining the true height of a web page, the device comprising: <b

[0035] a search module, used to find the minimum element of the target webpage containing the center position of the document based on a preset breadth-first algorithm; wherein the minimum element is the most basic HTML element located at the center position of the document in the target webpage;

[0036] an identification module, configured to identify the element with the maximum overflow height in the target webpage based on the minimum element; wherein the maximum overflow height is the element in the target webpage whose element content exceeds the height limit of its container, resulting in the appearance of a vertical scroll bar;

[0037] A determination module, used to obtain the maximum overflow height of the maximum overflow height element and the original page height of the target web page, and determine the real height of the target web page according to the maximum overflow height and the original page height.

[0038] In a third aspect, the present invention provides an electronic device, comprising: a memory and a processor; the memory is used to store a computer program; the processor is used to execute the computer program stored in the memory, so that the electronic device performs the steps of the method for determining the true height of a web page as described above.

[0039] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by an electronic device, implements the steps of the method for determining the true height of a web page as described above.

[0040] The above one or more technical solutions provided by the present invention may have the following advantages or at least achieve the following technical effects:

[0041] The present invention provides a method, device, equipment and medium for determining the true height of a web page. The method comprises: based on a preset breadth-first algorithm, searching layer by layer for the minimum element that contains the center position of a document on a target web page; wherein the minimum element is the most basic HTML element located at the center position of the document in the target web page; based on the minimum element, identifying the element with the maximum overflow height in the target web page; wherein the maximum overflow height is the element in the target web page whose element content exceeds the height limit of its container and causes the vertical scroll bar to appear; obtaining the maximum overflow height of the maximum overflow height element and the original page height of the target web page, and determining the true height of the target web page based on the maximum overflow height and the original page height. <bclass="d_n">

[0042] Thus, according to the web page HTML standard, the present invention finds out the element with the maximum overflow height by traversing, and then calculates the real height of the web page by adding the height of the overflow of the element with the maximum overflow height to the original web page height, solving the technical problems in the current web page forensics field, such as incomplete long screenshots or incomplete extraction of web page data by scrolling due to the lack of the real height of the web page. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] Figure 1 shows a schematic flow chart of a method for determining the real height of a web page in an embodiment of the present invention;

[0044] Figure 2 shows a schematic flow chart of finding the smallest element containing the center position of the document in an embodiment of the present invention;

[0045] Figure 3 shows a schematic flow chart of identifying the element with the maximum overflow height in an embodiment of the present invention;

[0046] Figure 4 shows a schematic flow chart of determining the real height of a target web page in an embodiment of the present invention;

[0047] Figure 5 shows a schematic flow chart of determining the real height of a target web page in an embodiment of the present invention;

[0048] <a href='javascript:;'Figure 6 shows a schematic diagram of the functional modules of the web page real height determination device in an embodiment of the present invention;

[0049] Figure 7 shows a schematic diagram of an electronic device in an embodiment of the present invention. Detailed implementation manners

[0050] The following uses specific specific examples to illustrate the implementation manners of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific implementation manners. Various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that, without conflict, the following embodiments and the features in the embodiments can be combined with each other.

[0051] It should be noted that the diagrams provided in the following embodiments only illustrate the basic concept of the present invention in a schematic manner. Therefore, only the components related to the present invention are shown in the diagrams, rather than being drawn according to the number, shape, and size of the components in actual implementation. The type, quantity, and ratio of each component in actual implementation can be arbitrarily changed, and the component layout type may also be more complex.

[0052] In the following description, a large number of details are discussed to provide a more thorough explanation of the embodiments of the present invention. However, it is obvious to those skilled in the art that the embodiments of the present invention can be implemented without these specific details. In other embodiments, well-known structures and devices are shown in the form of block diagrams rather than in detail to avoid making the embodiments of the present invention difficult to understand.

[0053] The terms "first", "second", etc. in the specification, claims, and above-mentioned drawings of the embodiments of the present disclosure are used to distinguish similar objects, and do not have to be used to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments of the present disclosure described here. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion.

[0054] Unless otherwise specified, the term "plurality" means two or more. <b

[0055] In the embodiments of the present disclosure, the character " / " indicates that the preceding and following objects are in an "or" relationship. For example, A / B indicates: A or B.

[0056] The term "and / or" is a kind of association relationship describing objects, indicating that three relationships may exist. For example, A and / or B means: A or B, or, A and B. For ease of understanding, the following first explains the relevant nouns or terms used in the embodiments of the present invention:

[0058] <1> , Framest is an HTML frame set element that is used to split the browser window into multiple frames (Frames), each of which can display different documents. Iframe is an element in HTML, which is used to embed another HTML page in the current page. It is an independent document that can load and display webpage content from different sources.

[0059] <2> , Overflow, used to control how the element content is displayed when it overflows its specified size (width or height).

[0061] The Overflow attribute can be applied to two sub-attributes, overflow-x and overflow-y, to control the horizontal and vertical overflow of an element respectively.

[0062] When using the overflow attribute, it is necessary to consider the size of the element, the size of the content, and the user's interaction needs with the content.

[0063] <3> , HTML (Hypertext Markup Language) is a standard markup language for creating web pages. It defines the structure and content of a web page, using tags to represent different elements, such as paragraphs, titles, links, pictures, etc.

[0064] <4> , Box Model, is a basic concept in CSS (Cascading Style Sheets), which describes how different parts (such as margins, borders, padding, and actual content) are combined to create elements on a web page. In the CSS box model, each element can be regarded as a rectangular box with the following properties:

[0065] 1. Content: This is the actual content area of ​​the element.

[0066] 2. Padding: The space around the content area. <bclass="d_n">

[0067] 3. Border: A line surrounding the padding and content.

[0068] 4. Margin: The space around an element that touches the borders or margins of other elements.

[0069] <5> , the center of the web page usually refers to the core area in the web page layout, where the most important content on the web page is placed.

[0069] <6> The "minimum element" at the center of a web page usually refers to the most basic visual or interactive elements that make up the core content and functionality of a web page. These elements are essential to ensure that users can quickly identify and access the key information of a web page. The following are some of the minimum elements that may be considered the center of a web page: logo, navigation links, main content, footer, and basic interactive elements.

[0071] <7> DOM (Document Object Model) is a programming interface for representing and manipulating HTML or XML documents. In the context of web pages, DOM is a component of a web page that converts the structured content of a web page (such as HTML tags) into a tree structure consisting of nodes and objects (such as elements, attributes, text, etc.), allowing web browsers to dynamically modify and interact with it through JavaScript. DOM represents an HTML document as a node tree, where each node represents an element or a text in the document. The DOM tree is organized in a hierarchical structure, where each node can contain child nodes, which can contain their own child nodes, forming a nested tree structure. The root node of the DOM tree is usually<html> element.

[0073] <8> , Breadth-First Search (BFS) algorithm is an algorithm for traversing or searching a tree or graph. Its basic idea is to start from the root node and traverse the nodes layer by layer until the target node is found or all nodes have been visited.

[0074] <9> , Client Height, refers to the height of the visible part of the element in the browser viewport, excluding the overflow part. It includes the inner height and inner margin of the element, but does not include the border and outer margin. The viewport height of the element can be obtained through JavaScript. Scroll HeightHeight) refers to the total height of the element's content, including the overflow part. It includes the internal height of the element, padding, and the height of the overflow content, but does not include the border and margin.

[0076] <10>, The original page height (Document Height) usually refers to the natural height of the page content, including the overflow part. For the entire document, the original web page height of the web page can be obtained through the document.documentElement.scrollHeight property.

[0077] Next, the technical solutions in the embodiments of the present invention will be described in detail with reference to the accompanying drawings in the embodiments of the present invention.

[0078] Please refer to Figure 1. An embodiment of the present invention provides a method for determining the real height of a web page. The method may include the following steps S10 to S30:

[0079] Step S10, based on a preset breadth-first algorithm, layer by layer, find the smallest element in the target web page that contains the center position of the document; wherein, the smallest element is the most basic HTML element located at the center position of the document in the target web page.

[0080] Among them, the target web page can be the current web page for which the real height is to be calculated.

[0081] The smallest element can be the most basic HTML element located at the center position of the target web page. Generally, it can be considered that the content at the most central position of the web page is the important content that the website wants to provide to users, and it is very likely to contain elements with height overflow.

[0082] In a specific implementation, the target web page can be regarded as a DOM tree, and all elements (nodes) of the DOM tree can be obtained; then, the breadth-first algorithm can be used to traverse all elements of the DOM tree layer by layer to find the smallest element in the target web page that contains the center position of the document.

[0083] Step S20, based on the smallest element, identify the element with the largest overflow height in the target web page; wherein, the largest overflow height is the element whose content in the target web page exceeds the height limit of its container and causes a vertical scroll bar to appear. <b

[0084] The maximum overflow height element may be an element whose content exceeds the height limit of its container in the target web page, resulting in the appearance of a vertical scroll bar.

[0085] In a specific implementation, the elements in the DOM tree can be traversed layer by layer according to the minimum element to identify the element with the maximum overflow height in the target web page.

[0086] As an example, when it is identified that the smallest element is a nested (iframe) element, the smallest element can be determined as the element with the maximum overflow height and returned directly.

[0087] As another example, when the minimum element is identified as an overflow element, it can be further identified whether the minimum element is a maximum overflow height element.

[0088] As yet another example, when it is identified that the smallest element is neither a nested (iframe) element nor an overflow (overflow) element, it may be further identified whether the parent element of the smallest element is an element with a maximum overflow height, and so on.

[0089] Step S30, obtaining the maximum overflow height of the maximum overflow height element and the original page height of the target webpage, and determining the real height of the target webpage according to the maximum overflow height and the original page height. Wherein , the maximum overflow height can be the height of the content area of ​​the maximum overflow element.It can be calculated by the difference between the scroll height of the maximum overflow element and the viewport height.

[0091] The original page height may be the natural height of the target web page content, and may include an overflow portion.

[0092] The real height can be the total height of the target web page content, which includes all visible and invisible parts (such as overflowing content).

[0093] In a specific implementation, the maximum overflow height of the maximum overflow height element and the original page height of the target page can be obtained first; and then the actual height of the target web page can be determined based on the sum of the maximum overflow height and the original page height.

[0094] Further, in one embodiment, after step S10, the following steps S40 to S50 may be included:

[0095] Step S40, based on the minimum element, identifying that there is no maximum height overflow element in the target web page; <b

[0096] Step S50, obtain the original page height of the target web page, and determine the original page height as the true height of the target web page.

[0097] In a specific implementation, elements in the DOM tree can be traversed layer by layer according to the smallest element to identify that there is no maximum overflow height element in the target web page; furthermore, when there is no maximum overflow height element, obtain the original page height of the target web page, and the original page height can be determined as the true height of the target web page.

[0098] In this embodiment, by using a preset breadth-first algorithm, the smallest element containing the document center position of the target web page is found layer by layer; based on the smallest element, the maximum overflow height element in the target web page is identified; obtain the maximum overflow height of the maximum overflow height element and the original page height of the target web page, and according to the maximum overflow height and the original page height. The present invention, according to the web page HTML standard, finds the maximum overflow height element by traversing, and then adds the height overflowed by the maximum overflow height element to the original web page height to calculate the true height of the web page, solving the technical problems in the current web page forensics field that due to the lack of the true height of the web page, long screenshots are incomplete, or the web page data extracted by scrolling is incomplete.

[0099] Based on the foregoing embodiment, a second embodiment of the method for determining the true height of a web page according to the present invention is proposed. Please refer to Figure 2. In this embodiment, step S10 may further include the following sub-steps S101 to S104:

[0100] Sub-step S101, create an element queue, add the root node of the target web page to the element queue, and add all child nodes of the root node to the element queue.

[0101] Among them, the root node, in an HTML document, the root node is usually the <html> element. It contains the entire content of the web page.

[0102] In the DOM tree of the target web page, each element can have child nodes, and these child nodes can have their own child nodes. In the DOM tree, the level of a node is defined by its distance from the root node. The root node is at level 0, the child nodes of the root node are at level 1, the child nodes of the child nodes are at level 2 (that is, the grandchildren of the root node, located two levels below the root node), and so on. <b

[0103] Element queue may refer to a data structure for storing elements, which follows the first-in-first-out principle. When executing certain DOM tree traversal or operation algorithms, the root node is placed in the element queue as the first element to start processing.

[0104] In a specific implementation, an element queue may be created first. During initialization, the root node of the target web page is added to the element queue. Then, all child nodes of the root node are enumerated, and then all child nodes of the root node may be added to the element queue, and the element queue is updated.

[0105] Sub-step S102, for each element in the element queue, determines whether the coordinates of the element include the center position of the document.

[0106] In a specific implementation, for each element in the element queue, it can be determined whether the coordinates of each element include the center position of the document, so as to find out the element of the target web page that includes the center position of the document.

[0107] Sub-step S103, when it is detected that the coordinates of the element include the center position of the document, detect whether the element has a child node.

[0108] In a specific implementation, when it is detected that the coordinates of the element include the center position of the document, it is further detected whether the element contains a child node to determine whether the element is the minimum element.

[0109] Sub-step S104, when it is detected that the element has no child node, the element is determined as the smallest element of the target web page that contains the center position of the document.

[0110] In a specific implementation, when it is detected that the element has no child node, it can be determined that the element is the minimum element.

[0111] Further, in one embodiment, after the step S102, the following sub-steps S105 to S106 may be included:

[0112] Sub-step S105, when it is detected that the coordinates of the element do not include the center position of the document, adding all child nodes of the element to the element queue;

[0113] Sub-step S106, cyclically executing the step of determining whether the coordinates of each element in the element queue contain the center position of the document, until the element queue is empty, and traversal ends. <bclass="d_n">

[0114] In a specific implementation, when it is detected that the coordinates of the element do not include the center position of the document, all child nodes of the element can be enumerated, and all child nodes of the element can be added to the element queue to update the element queue; then, the step of determining whether the coordinates of the element include the center position of the document can be executed in a loop for each element in the element queue until the element queue is empty, and the traversal is terminated to return the smallest element of the target web page that includes the center position of the document.

[0115] Further, in one embodiment, after the step S103, the following sub-steps S107 to S108 may be included:

[0116] Sub-step S107, when it is detected that the element has child nodes, adding all child nodes of the element to the element queue;

[0117] Sub-step S108, loopingly executing the step of determining whether the coordinates of each element in the element queue contain the center position of the document, until the smallest element of the target web page containing the center position of the document is identified, and traversal ends.

[0118] In a specific implementation, when it is detected that the element has child nodes, all child nodes of the element can be enumerated, and all child nodes of the element can be added to the element queue to update the element queue; then, the step of determining whether the coordinates of the element include the center position of the document can be executed in a loop for each element in the element queue until the element queue is empty, and the traversal is terminated to return the smallest element of the target web page that includes the center position of the document.

[0119] In this embodiment, an element queue is created, and the root node of the target webpage is added to the element queue, and all the child nodes of the root node are added to the element queue; for each element in the element queue, it is determined whether the coordinates of the element include the center position of the document; when it is detected that the coordinates of the element include the center position of the document, it is detected whether the element has a child node; when it is detected that the element does not have a child node, the element is determined as the minimum element of the target webpage that includes the center position of the document. Thus, the minimum element of the target webpage that includes the center position of the document is found layer by layer by using the breadth-first algorithm, and then the real height of the target webpage is further calculated using the minimum element, thereby improving the efficiency of calculating the real height of the target webpage.

[0120] Based on the above embodiments, a third embodiment of the method for determining the true height of a web page of the present invention is proposed. <a href='javascript:;' class="see-img-anchor" img-id="HDA0004936782970000021"img-title="Figure 3">Figure 3, in this embodiment, step S20 may include the following sub-steps S201 to S205:

[0121] Sub-step S201, determining whether the minimum element is a nested element.

[0122] Among them, the nested (iframe) element can refer to an element located inside another element to form a hierarchical structure.

[0123] In a specific implementation, it can be determined first whether the smallest element is a nested element.

[0124] Sub-step S202: If the minimum element is a nested element, the minimum element is determined as the element with the maximum overflow height in the target web page.

[0125] In a specific implementation, when it is determined that the smallest element is a nested (iframe) element, the smallest element can be determined as the element with the maximum overflow height and directly returned.

[0126] Sub-step S203: on the contrary, if the minimum element is not a nested element, determine whether the minimum element is an overflow element. Wherein , overflow (overflow) element, can refer to its content exceeds the size of element itself, causes content part or all to be invisible. Overflow can be horizontal (content exceeds the width of element) or vertical (content exceeds the height of element).

[0128] In a specific implementation, on the contrary, when it is determined that the smallest element is not a nested (iframe) element, it is further determined whether the smallest element is an overflow (overflow) element.

[0129] Sub-step S204, if the minimum element is an overflow element, and when it is detected that there is no record of an overflow height element, record the minimum element as the maximum overflow height element.

[0130] In a specific implementation, when it is determined that the minimum element is an overflow element, it is further determined whether there is already a record of an element with overflow height; and when it is detected that there is no record of an element with overflow height, the overflow height of the minimum element is recorded as the maximum overflow height, that is, the minimum element is the element with maximum overflow height, and is returned directly. <b

[0131] In addition, when a record of an overflow height element is detected, the overflow height of the minimum element is compared with the overflow height of the overflow height element, and then the element with the maximum overflow height is recorded. It should be noted that the element with the maximum overflow height is always recorded.

[0132] Sub-step S205, on the contrary, if the minimum element is not an overflow element, then the parent element of the minimum element is taken, and when the parent element is not empty, the parent element is set as the minimum element, and the step of determining whether the minimum element is a nested element is executed in a loop until the element with the maximum overflow height in the target web page is identified, and the traversal is terminated.

[0133] Among them, the parent element is empty, which may mean that in the HTML document, a certain element has no direct parent element.

[0134] It should be noted that in the DOM tree, each element has a parent element, which contains the current element. If an element has no parent element, it means that the element is at the top of the DOM tree, that is, the element is the root element (node) of the HTML document.

[0135] In a specific implementation, when it is determined that the minimum element is not an overflow element, the parent element of the minimum element is obtained, and it is determined whether the parent element is empty; and when the parent element is not empty, the parent element is set as the minimum element, and the step of determining whether the minimum element is a nested element is executed in a loop until the element with the maximum overflow height in the target web page is identified, and the traversal is terminated.

[0136] In addition, when the parent element is empty, the traversal is terminated, and it can be determined that there is no element with the maximum overflow height in the target web page. <b

[0137] In this embodiment, by determining whether the smallest element is a nested element; if the smallest element is a nested element, then determining the smallest element as the element with the maximum overflow height in the target web page; conversely, if the smallest element is not a nested element, then determining whether the smallest element is an overflow element; if the smallest element is an overflow element, and when no record of an element with an overflow height is detected, recording the smallest element as the element with the maximum overflow height; conversely, if the smallest element is not an overflow element, taking the parent element of the smallest element, and when the parent element is not empty, setting the parent element as the smallest element, and looping to execute the step of determining whether the smallest element is a nested element until the element with the maximum overflow height in the target web page is identified, and ending the traversal. Thus, the element with the maximum overflow height can be quickly found through traversal, and it is not necessary to traverse all elements of the web page. Only by preprocessing the elements containing the center position of the document, a large number of irrelevant elements are excluded, thereby improving the speed of calculating the true height of the web page.

[0138] Based on the foregoing embodiment, a fourth embodiment of the method for determining the true height of a web page according to the present invention is proposed. Please refer to Figure 4. In this embodiment, step S30 may include the following sub-steps S301 to S303:

[0139] Sub-step S301, when the element with the maximum overflow height is an overflow element, obtaining the viewport height and the scroll height of the element with the maximum overflow height, and obtaining the original page height of the target web page.

[0140] Among them, the viewport height may refer to the height of the maximum overflow element relative to the visible part in the browser viewport.

[0141] The scroll height may be the total height of the content of the maximum overflow element.

[0142] In a specific implementation, the type of the element with the maximum overflow height may be determined first, and then when it is determined that the element with the maximum overflow height is an overflow element, the viewport height and the scroll height of the element with the maximum overflow height, and the original page height of the target web page may be obtained.

[0143] Sub-step S302, determining the maximum overflow height according to the difference between the scroll height and the viewport height.

[0144] Among them, the maximum overflow height may be the overflow height of the element with the maximum overflow height.<b

[0145] In a specific implementation, the difference between the scroll height and the viewport height can be calculated, and then the difference between the scroll height and the viewport height can be determined as the maximum overflow height.

[0146] Sub-step S303: Determine the true height of the target web page according to the sum of the original web page height and the maximum overflow height.

[0147] In a specific implementation, the sum of the original web page height and the maximum overflow height can be calculated, and then the sum of the original web page height and the maximum overflow height can be determined as the true height of the target web page.

[0148] In this embodiment, when the maximum overflow height element is an overflow element, the viewport height, the scroll height of the maximum overflow height element, and the original page height of the target web page are obtained; the maximum overflow height is determined according to the difference between the scroll height and the viewport height; the true height of the target web page is determined according to the sum of the original web page height and the maximum overflow height. Thus, when the maximum overflow height element is an overflow element, the true height of the target web page is accurately calculated according to the overflow height of the maximum overflow height element and the original web page height of the target web page.

[0149] Based on the foregoing embodiments, a fifth embodiment of the method for determining the true height of a web page according to the present invention is proposed. Please refer to Figure 5. In this embodiment, step S30 may further include the following sub-steps S304 to S306:

[0150] Sub-step S304: When the maximum overflow height element is a nested element, enter the internal content of the nested element to continue traversing, set the internal content of the nested element as the target web page, and loop through the steps of finding the smallest element containing the document center position of the target web page layer by layer based on a preset breadth-first algorithm to the step of determining the type of the maximum overflow height element until the maximum overflow height element of the internal content is identified, and then end the traversal.<bclass="d_n">

[0151] In a specific implementation, when it is determined that the element with the maximum overflow height is a nested element, the internal content of the nested element can be entered to continue traversal; the internal content of the nested element is then set as the target web page, and the steps of searching layer by layer for the minimum element containing the center position of the document on the target web page based on a preset breadth-first algorithm to the step of identifying the element with the maximum overflow height in the target web page are cyclically executed until the element with the maximum overflow height of the internal content is identified, and the traversal is terminated.

[0152] Sub-step S305, determining whether the maximum overflow height element of the internal content is an overflow element, and when the maximum overflow height element is an overflow element, obtaining the viewport height and scrolling height of the maximum overflow height element and obtaining the original page height of the target web page.

[0153] In a specific implementation, it is possible to first determine whether the maximum overflow height element of the internal content is an overflow element; then, when it is determined that the maximum overflow height element of the internal content is an overflow element, obtain the viewport height and scroll height of the maximum overflow height element, and obtain the original page height of the target web page.

[0154] Sub-step S306, determining the maximum overflow height according to the difference between the scroll height and the viewport height, and determining the actual height of the target web page according to the sum of the original web page height and the maximum overflow height.

[0155] In a specific implementation, the difference between the scrolling height and the viewport height can be calculated, and then the difference between the scrolling height and the viewport height can be determined as the maximum overflow height; the sum of the original web page height and the maximum overflow height can be calculated, and then the sum of the original web page height and the maximum overflow height can be determined as the actual height of the target web page.

[0156] In this embodiment, when the element with the maximum overflow height is a nested element, the internal content of the nested element is entered and traversed to identify the element with the maximum overflow height in the internal content; then, based on the overflow height of the element with the maximum overflow height and the original web page height of the target web page, the actual height of the target web page is accurately calculated.

[0157] Based on the same inventive concept, the sixth embodiment of the present invention also provides a webpage real height determination device corresponding to the webpage real height determination method of the previous embodiment. Since the principle of solving the problem by the device in the sixth embodiment of the present invention is similar to the webpage real height determination method of the previous embodiment of the present invention, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be repeated. Please refer to <a href='javascript:;' class="see-img-anchor"Figure 6. The device for determining the true height of a web page according to the present invention may include:

[0158] A search module 10, configured to search layer by layer for the smallest element in the target web page that contains the center position of the document based on a preset breadth-first algorithm; wherein, the smallest element is the most basic HTML element located at the center position of the document in the target web page;

[0159] An identification module 20, configured to identify the element with the maximum overflow height in the target web page based on the smallest element; the maximum overflow height is the element in the target web page where the element content exceeds the height limit of its container, resulting in the appearance of a vertical scroll bar;

[0160] A determination module 30, configured to obtain the maximum overflow height of the element with the maximum overflow height and the original page height of the target web page, and determine the true height of the target web page according to the maximum overflow height and the original page height.

[0161] In addition, the present invention also provides a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, the above method for determining the true height of a web page is implemented.

[0162] Figure 7 is a schematic block diagram of an electronic device provided by an embodiment of the present application. As shown in Figure 7, the electronic device includes: at least one processor 401, a memory 402, at least one network interface 403, and a user interface 405. Each component in the electronic device is coupled together through a bus system 404. It can be understood that the bus system 404 is used to realize the connection and communication between these components. In addition to including a data bus, the bus system 404 also includes a power bus, a control bus, and a status signal bus. However, for the sake of clear illustration, in <a href='javascript:;' class="see-img-anchor" img-id="HDA0004936782970000041"In Figure 7, various buses are marked as bus systems.

[0163] Among them, the user interface 405 may include a display, keyboard, mouse, trackball, click gun, keys, buttons, touch pad or touch screen, etc. It is understood that the memory 402 can be a volatile memory or a non-volatile memory, and can also include both volatile and non-volatile memories. Wherein, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), which is used as an external cache. By way of exemplary but not restrictive explanation, many forms of RAM are available, such as static random access memory (SRAM), synchronous static random access memory (SSRAM). The memory described in the embodiment of the present invention is intended to include but is not limited to these and any other memory suitable for the category.

[0165] The memory 402 in the embodiment of the present invention is used to store various types of data to support the operation of the electronic device 400. Examples of these data include: any executable program for operating on the electronic device 400, such as an operating system 4021 and an application 4022; the operating system 4021 includes various system programs, such as a framework layer, a core library layer, a driver layer, etc., for implementing various basic services and processing hardware-based tasks. The application 4022 may include various applications, such as a media player (Media Player), a browser (Browser), etc., for implementing various application services. The webpage real height determination method provided in the embodiment of the present invention may be included in the application 4022.

[0166] The method disclosed in the above embodiment of the present invention can be applied to the processor 401, or implemented by the processor 401. The processor 401 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by an integrated logic circuit of hardware in the processor 401 or an instruction in the form of software. The above processor 401 may be a general-purpose processor, a digital signal processor (DSP, Digital Signal Processor) or a processor 401.Processor), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Processor 401 can implement or execute the methods, steps and logic block diagrams disclosed in the embodiments of the present invention. General processor 401 can be a microprocessor or any conventional processor, etc. In combination with the steps of the method for determining the true height of a web page provided in the embodiments of the present invention, it can be directly embodied as a hardware decoding processor to be executed, or a combination of hardware and software modules in the decoding processor to be executed. The software module can be located in a storage medium, which is located in a memory, and the processor reads the information in the memory and completes the steps of the aforementioned method in combination with its hardware.

[0167] In an exemplary embodiment, the electronic device 400 can be used by one or more application-specific integrated circuits (ASIC), DSP, programmable logic device (PLD), complex programmable logic device (CPLD) to execute the aforementioned method.

[0168] The above is only a specific embodiment of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or replacements within the technical scope disclosed in the present application, which 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.

[0169] In summary, the present invention is based on the HTML standard of the web page, and finds the maximum overflow height element by traversal, and then adds the original web page height to the overflow height of the maximum overflow height element to calculate the real height of the web page, which solves the current technical problems in the field of web page forensics, such as incomplete long screenshots or incomplete scrolling web page data due to the lack of the real height of the web page.

[0170] The above embodiments are merely illustrative of the principles and effects of the present invention, and are not intended to limit the present invention. Any person familiar with the technology may modify or change the above embodiments without violating the spirit and scope of the present invention. Therefore, all equivalent modifications or changes made by those with ordinary knowledge in the art without departing from the spirit and technical ideas disclosed by the present invention should still be covered by the claims of the present invention.< / iframe>

Claims

1. A method for determining the true height of a web page, characterized in that: The method comprises: Based on a preset breadth-first algorithm, the minimum element of the target webpage containing the center position of the document is searched layer by layer; wherein the minimum element is the most basic HTML element located at the center position of the document in the target webpage; Based on the minimum element, identifying the element with the maximum overflow height in the target webpage; wherein the element with the maximum overflow height is the element in the target webpage whose element content exceeds the height limit of its container and causes the vertical scroll bar to appear; The maximum overflow height of the maximum overflow height element and the original page height of the target webpage are acquired, and the real height of the target webpage is determined according to the maximum overflow height and the original page height.

2. The method according to claim 1, characterized in that The method of searching layer by layer for the smallest element of the target webpage containing the center position of the document based on the preset breadth-first algorithm includes: Creating an element queue, adding the root node of the target webpage to the element queue, and adding all child nodes of the root node to the element queue; For each element in the element queue, determining whether the coordinates of the element include the center position of the document; When it is detected that the coordinates of the element include the center position of the document, detecting whether the element has a child node; When it is detected that the element has no child node, the element is determined to be the smallest element that contains the center position of the document of the target web page.

3. The method according to claim 2, characterized in that After the step of determining, for each element in the element queue, whether the coordinates of the element include the center position of the document, the method further includes: When it is detected that the coordinates of the element do not include the center position of the document, all child nodes of the element are added to the element queue; The step of determining whether the coordinates of each element in the element queue contain the center position of the document is executed in a loop until the element queue is empty, and the traversal is terminated.

4. The method according to claim 1, characterized in that: The step of identifying the element with the maximum overflow height in the target webpage based on the minimum element includes: Determine whether the minimum element is a nested element; If the minimum element is a nested element, the minimum element is determined as the element with the maximum overflow height in the target webpage; On the contrary, if the minimum element is not a nested element, determining whether the minimum element is an overflow element; If the minimum element is an overflow element, and when it is detected that there is no record of an overflow height element, the minimum element is recorded as the maximum overflow height element; On the contrary, if the minimum element is not an overflow element, the parent element of the minimum element is taken, and when the parent element is not empty, the parent element is set as the minimum element, and the step of determining whether the minimum element is a nested element is executed repeatedly until the element with the maximum overflow height in the target web page is identified and the traversal is terminated.

5. The method according to claim 1, characterized in that The obtaining of the maximum overflow height of the maximum overflow height element and the original page height of the target webpage, and determining the real height of the target webpage according to the maximum overflow height and the original page height, includes: When it is determined that the maximum overflow height element is an overflow element, obtaining the viewport height and the scroll height of the maximum overflow height element and obtaining the original page height of the target webpage; Determine a maximum overflow height according to a difference between the scroll height and the viewport height; The actual height of the target webpage is determined according to the sum of the original webpage height and the maximum overflow height.

6. The method according to any one of claims 1 to 4, characterized in that: The obtaining of the maximum overflow height of the maximum overflow height element and the original page height of the target webpage, and determining the real height of the target webpage according to the maximum overflow height and the original page height, includes: When the maximum overflow height element is a nested element, enter the internal content of the nested element to continue traversing, set the internal content of the nested element as the target web page, and cyclically execute the steps of searching layer by layer for the minimum element containing the center position of the document on the target web page based on a preset breadth-first algorithm to the step of determining the type of the maximum overflow height element, until the maximum overflow height element of the internal content is identified, and the traversal ends; Determine whether the maximum overflow height element of the internal content is an overflow element, and if the maximum overflow height element is an overflow element, obtain the viewport height and scroll height of the maximum overflow height element and obtain the original page height of the target webpage; The maximum overflow height is determined according to the difference between the scroll height and the viewport height, and the real height of the target web page is determined according to the sum of the original web page height and the maximum overflow height.

7. The method according to claim 1, characterized in that After the step of finding the minimum element of the target webpage including the center position of the document, the method further includes: Based on the minimum element, identifying that there is no maximum height overflow element in the target webpage; The original page height of the target webpage is obtained, and the original page height is determined as the real height of the target webpage.

8. A device for determining the true height of a web page, characterized in that: The device comprises: A search module, used to search layer by layer for the smallest element in the center of the document of the target webpage based on a preset breadth-first algorithm; wherein the smallest element is the most basic HTML element located in the center of the document of the target webpage; an identification module, configured to identify the element with the maximum overflow height in the target webpage based on the minimum element; wherein the maximum overflow height is the element in the target webpage whose element content exceeds the height limit of its container, resulting in the appearance of a vertical scroll bar; The determination module is used to obtain the maximum overflow height of the maximum overflow height element and the original page height of the target webpage, and determine the real height of the target webpage according to the maximum overflow height and the original page height.

9. An electronic device, characterized in that: The electronic device comprises: a memory and a processor, wherein the memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory, so that the electronic device performs the steps of the method as claimed in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a program, and when the program is run, it is used to implement the steps of the method according to any one of claims 1 to 7.

Citation Information

Cited By

  • Screenshot method, electronic device, and storage medium

    WO2026179835A1