Page content positioning method and device, storage medium and electronic equipment
By setting anchor points with zero-width characters, responsive to the click operation of the target object, obtaining and displaying the target string, the problem of insufficient positioning accuracy of target characters on the web page in the existing technology is solved, and the problem of insufficient positioning accuracy of target characters on the web page is achieved without affecting the page loading speed , accurately locate every character in the web page.
Patent Information
- Application Number
- CN202411363526.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-27
- Publication Date
- 2024-12-17
AI Technical Summary
In the prior art, the method of character wrapping labels is used to realize the target character positioning of Web pages, resulting in complex code structure, low page loading speed, and the inability to accurately locate specific text strings.
By setting anchor points with zero width characters, responding to the target object's clicking operation of the target positioning component in the web page, obtaining preset id information and preset zero width string, determining the target text node, and displaying the target string according to the location information. Accurate positioning within the visual area of the web page.
Without changing the page hierarchy structure and loading speed, the precise positioning of every character in the web page is achieved, which improves the user interaction experience and solves the problem of low page loading speed caused by complex code structure.
Smart Images

Figure CN119149853A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of Internet technology, and in particular to a method, device, storage medium and electronic device for locating page content. Background Art
[0002] In order to improve the user-friendliness of web pages, many web services set anchors and corresponding links / buttons in the page, allowing users to quickly scroll the page to a specified position by clicking these links / buttons. This function is usually called anchor positioning. Common anchor positioning includes "Back to Top" in long pages and menus within the page. However, the anchor setting method of these functions is to add attributes to specific element nodes, that is, the anchor positioning accuracy is the element node, and it is impossible to accurately locate a specific text string.
[0003] In order to improve the accuracy of anchor point positioning, the prior art adopts the method of wrapping characters with tags. In the Hypertext Markup Language (HTML) encoding stage, the original complete text node is cut into multiple nodes, and the target string to be located is wrapped in the tag to achieve fast positioning of the target character. This method will destroy the HTML structure of the Web page, and more element nodes and text nodes need to be created, making the Document Object Model (DOM) tree complicated. Too many node creations will reduce the speed of page loading and cause jams.
[0004] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention
[0005] The embodiments of the present invention provide a method, device, storage medium and electronic device for locating page content, so as to at least solve the technical problem that the target character positioning of a Web page is achieved by wrapping characters with tags in the prior art, and the code structure is complex, resulting in a low page loading speed.
[0006] According to one aspect of an embodiment of the present invention, a method for locating page content is provided, comprising: in response to a click operation of a target object on a target locating component in a Web page, obtaining preset ID information and a preset zero-width character string corresponding to the target locating component; determining a target text node based on the preset ID information and the preset zero-width character string, wherein the text character string of the target text node contains a target character string to be located, and a zero-width character string that is the same as the preset zero-width character string; determining position information of the target character string in the text character string of the target text node, and determining coordinate information of the target character string on the Web page based on the position information; and displaying the target character string in a visible area of the Web page based on the coordinate information of the target character string on the Web page.
[0007] Furthermore, the target text node is determined based on preset id information and a preset zero-width character string, including: based on the preset id information, determining the target element node in the DOM tree corresponding to the web page, wherein the target element node is an element node having an id attribute identical to the preset id information; based on the preset zero-width character string, determining the target text node from multiple child nodes of the target element node.
[0008] Furthermore, based on a preset zero-width string, a target text node is determined from multiple child nodes of the target element node, including: comparing the preset zero-width string with the text string stored in the node attributes of each child node respectively; and taking the child node whose text string contains the same zero-width string as the preset zero-width string as the target text node.
[0009] Furthermore, the position information of the target string in the text string of the target text node is determined, including: determining the index information of the target string in the text string of the target text node based on the index information of a zero-width string that is the same as a preset zero-width string in the text string of the target text node and the length information of the zero-width string; performing de-encoding and parsing processing on the zero-width string to obtain the length information of the target string; and composing the position information based on the index information of the target string in the text string of the target text node and the length information of the target string.
[0010] Furthermore, based on the coordinate information of the target character string in the Web page, the target character string is displayed in the visible area of the Web page, including: determining a rectangular area corresponding to the target character string in the Web page based on the coordinate information; determining a positional relationship between the rectangular area and the visible area, and determining a target offset of the scroll bar based on the positional relationship and current position information of the scroll bar of the Web page; and adjusting the position of the scroll bar based on the target offset to display the target character string in the visible area of the Web page.
[0011] Furthermore, before responding to the target object's click operation on the target positioning component in the Web page, the method also includes: in the HTML file corresponding to the Web page, configuring the id attribute of the tag where the target string is located based on preset id information, and inserting a preset zero-width string before the target string to achieve anchor point setting for the Web page.
[0012] Furthermore, a preset zero-width string is obtained through the following steps: a source string is constructed based on the id attribute of the tag where the target string is located, the index of the target string under the current element node, and the length of the target string; each character in the source string is converted into a binary string to obtain multiple binary strings corresponding to the source string; for each binary string, a first number in the binary string is replaced based on a first zero-width character, and a second number in the binary string is replaced based on a second zero-width character to obtain a zero-width string corresponding to each binary string; and the zero-width strings corresponding to each binary string are connected based on a third zero-width character to obtain a preset zero-width string.
[0013] According to another aspect of an embodiment of the present invention, a device for locating page content is also provided, including: an acquisition module, used to respond to a click operation of a target object on a target positioning component in a Web page, and acquire preset ID information and a preset zero-width character string corresponding to the target positioning component; a first determination module, used to determine a target text node based on the preset ID information and the preset zero-width character string, wherein the text character string of the target text node contains a target character string to be located, and a zero-width character string that is the same as the preset zero-width character string; a second determination module, used to determine position information of the target character string in the text character string of the target text node, and determine coordinate information of the target character string on the Web page based on the position information; and a processing module, used to display the target character string in a visible area of the Web page based on the coordinate information of the target character string on the Web page.
[0014] According to another aspect of an embodiment of the present invention, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the computer program implements the above-mentioned method for locating page content.
[0015] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the above-mentioned method for locating page content when running.
[0016] According to another aspect of an embodiment of the present invention, an electronic device is also provided, which includes one or more processors; a memory for storing one or more programs, which, when the one or more programs are executed by the one or more processors, enables the one or more processors to run the programs, wherein the programs are configured to execute the above-mentioned method for locating page content during runtime.
[0017] In an embodiment of the present invention, a method of setting an anchor point by using a zero-width character is adopted. First, a click operation of a target object on a target positioning component in a Web page is responded to, preset ID information and a preset zero-width character string corresponding to the target positioning component are obtained, and then a target text node is determined based on the preset ID information and the preset zero-width character string, wherein the text string of the target text node contains a target character string to be located and a zero-width character string that is the same as the preset zero-width character string, and then the position information of the target character string in the text string of the target text node is determined, and the coordinate information of the target character string on the Web page is determined based on the position information, and then the target character string is displayed in a visible area of the Web page based on the coordinate information of the target character string on the Web page.
[0018] In the above process, the zero-width character encoding technology is used to set the anchor point in the text node, and the target text node can be determined according to the preset ID information and the preset zero-width character string, so that the target character string can be displayed in the visible area of the Web page, and each character in the Web page can be accurately located without changing the page hierarchy structure, giving users a better interactive experience.
[0019] It can be seen that through the technical solution of the present invention, the purpose of realizing rapid positioning with accuracy to a specific character string is achieved without changing the structure of the original HTML of the Web page and the page loading speed, thereby achieving the technical effect of improving the accuracy of rapid positioning within the page from the element node level to the character level without affecting the original DOM structure of the page and the loading speed of the page, thereby solving the technical problem in the prior art of using character wrapping tags to achieve target character positioning of the Web page, which has a complex code structure and leads to a low page loading speed. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0021] Figure 1 is a flow chart of an optional method for locating page content according to an embodiment of the present invention;
[0022] Figure 2 is a schematic diagram of states of page elements in an optional Web page according to an embodiment of the present invention;
[0023] Figure 3 It is a schematic diagram of an optional process of using zero-width characters to set an anchor point for precise positioning within a page according to an embodiment of the present invention;
[0024] Figure 4is a schematic diagram of an optional device for locating page content according to an embodiment of the present invention;
[0025] Figure 5 is a schematic diagram of an optional electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0026] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings 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 should fall within the scope of protection of the present invention.
[0027] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0028] It should be noted that the relevant information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for display, data for analysis, etc.) involved in the present invention are all information and data authorized by the user or fully authorized by all parties. For example, an interface is set between the system and the relevant user or organization. Before obtaining relevant information, it is necessary to send an acquisition request to the aforementioned user or organization through the interface, and obtain relevant information after receiving the consent information fed back by the aforementioned user or organization.
[0029] The embodiments or examples of the present disclosure are not exhaustive, but are only illustrative of some embodiments or examples, and are not intended to be specific limitations on the scope of protection of the present disclosure. In the absence of contradiction, each step in a certain embodiment or example can be implemented as an independent example, and the steps can be combined arbitrarily. For example, the scheme after removing some steps in a certain embodiment or example can also be implemented as an independent example, and the order of the steps in a certain embodiment or example can be arbitrarily exchanged. In addition, the optional methods or optional examples in a certain embodiment or example can be combined arbitrarily; in addition, the various embodiments or examples can be combined arbitrarily, for example, some or all steps of different embodiments or examples can be combined arbitrarily, and a certain embodiment or example can be combined arbitrarily with the optional methods or optional examples of other embodiments or examples.
[0030] Example 1
[0031] According to an embodiment of the present invention, an embodiment of a method for locating page content is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0032] Figure 1 is a flow chart of an optional method for locating page content according to an embodiment of the present invention, such as Figure 1 As shown, the method comprises the following steps:
[0033] Step S101, in response to a target object's click operation on a target positioning component in a Web page, obtain preset ID information and a preset zero-width character string corresponding to the target positioning component.
[0034] In the above steps, an application system, a processor, an electronic device or the like can be used as an execution subject. For example, the positioning system of the page content responds to the click operation of the target object (such as a user) on the target positioning component (such as a link or a button) in the Web page, and obtains the preset id information and the preset zero-width string corresponding to the target positioning component, wherein the preset id information can be a preset id number, and the preset zero-width string can be generated according to the target information of the target string (such as id number, index, offset, etc.), index is the index of the target string under the current element node, indicating that the target string is the nth string to be located under the current element node, and offset is the length of the target string.
[0035] In an optional embodiment, before responding to the target object's click operation on the target positioning component in the Web page, in the HTML file corresponding to the Web page, the id attribute of the tag where the target string is located is configured based on preset id information, and a preset zero-width string is inserted before the target string to achieve the anchor point setting of the Web page.
[0036] A prepended zero-width character string is a character string formed by one or more prepended zero-width characters.
[0037] Optionally, before responding to the target object's click operation on the target positioning component in the Web page, first set an anchor point to mark the content that needs to be quickly located in the original Web page, that is, the target string. By setting the id attribute for the tag that directly wraps the target string in the HTML file corresponding to the Web page, that is, configuring a preset id number (unique in the HTML document), and inserting a preset zero-width string before the target string, the anchor point setting of the Web page is achieved. Among them, the preset zero-width string marks the starting position of the target string, and the preset zero-width string is unique among all text nodes under its parent tag.
[0038] In an optional embodiment, a preset zero-width string is obtained by the following steps: a source string is constructed based on the id attribute of the tag where the target string is located, the index of the target string under the current element node, and the length of the target string; each character in the source string is converted into a binary string to obtain multiple binary strings corresponding to the source string; for each binary string, a first number in the binary string is replaced based on a first zero-width character, and a second number in the binary string is replaced based on a second zero-width character to obtain a zero-width string corresponding to each binary string; and the zero-width strings corresponding to each binary string are connected based on a third zero-width character to obtain a preset zero-width string.
[0039] Zero-width characters (also known as: zero-width characters) are a special type of character that does not display any visible content in the text, so it does not interfere with the readability of the text within the page. There are four standard zero-width characters: zero-width space, zero-width non-ligature, zero-width ligature, and zero-width hyphenation. Among them, zero-width space is represented by ";" in HTML, which is used to insert spaces without displaying any characters, and is often used to force line breaks without breaking words. Zero-width non-ligatures are represented by ";" in HTML, and are often used to prevent character connection in some languages. Zero-width ligatures are represented by ";" in HTML, which are used to force character connection in some languages, as opposed to zero-width non-ligatures. Zero-width hyphenation is represented by ";" in HTML, which is used to prevent character connection without creating visible spacing.
[0040] Considering that directly using the combination of the above four zero-width characters to construct a zero-width string, there are the following problems: the combination has no rules and it is difficult to ensure uniqueness; the combination is meaningless and cannot provide additional information, such as the length of the target string. Therefore, in an embodiment of the present invention, a unique and meaningful string is converted into a zero-width string through the following steps: first, based on the id attribute of the label where the target string is located, the index of the target string under the current element node, and the length of the target string, a source string is constructed, and the source string is expressed as ${id}_${index}_${offset}, where id is the id attribute on the label that wraps the target string, index is the index of the target string under the current element node, and identifies the target string as the string that needs to be located under the current element node, and offset is the length of the target string, which is used for subsequent construction of a Range object. For example, if id is section1, index is 1, and offset is 5, then the source string is section1_1_5.
[0041] Then, each character in the source string is converted into a binary string to obtain multiple binary strings corresponding to the source string. For each binary string, the first digit (for example, the first digit is 0) in the binary string is replaced based on the first zero-width character (for example, the first zero-width character is ;), that is, ";" is used to replace "0", and the second digit (for example, the second digit is 1) in the binary string is replaced based on the second zero-width character (for example, the second zero-width character is ;), that is, ";" is used to replace "1" to obtain the zero-width string corresponding to each binary string, and then the zero-width string corresponding to each binary string is connected according to the third zero-width character (for example, the third zero-width character is ;) to obtain a preset zero-width string, that is, multiple zero-width strings are spliced with the third zero-width character as the connector to form a complete zero-width string.
[0042] It can be understood that, for multiple binary strings corresponding to a source string, when zero-width strings corresponding to the multiple binary strings are concatenated, the concatenation order is determined based on the positions of the characters corresponding to the respective binary strings in the source string.
[0043] It should be noted that by constructing a clear and unique source string based on the id attribute of the tag where the target string is located, the index of the target string under the current element node, and the length of the target string, the final zero-width string can be guaranteed to be unique, and valid relevant information can be obtained after being de-encoded.
[0044] In some examples, the present invention can be applied to a document review system. For an online document, a text string in a paragraph may occupy many lines. In this paragraph, there may be multiple strings with modification suggestions. When a user clicks on a modification suggestion, he or she hopes to quickly locate the string associated with the suggestion. By giving the paragraph a label (such as Tags or The id attribute is added to the tag, and a zero-width string is added before the character or string on which comments are made. Since zero-width characters are invisible to users and do not affect the normal reading of the document, they can help users quickly locate the string on which comments are made.
[0045] Step S102 , determining a target text node according to preset ID information and a preset zero-width character string, wherein the text character string of the target text node includes a target character string to be located and a zero-width character string that is the same as the preset zero-width character string.
[0046] Optionally, the target text node can be determined based on preset ID information and a preset zero-width string. For example, the element node that directly wraps the target string can be found based on the preset ID number, and the text node (i.e., the target text node) containing a specific zero-width string (i.e., the preset zero-width string) can be found from the multiple child nodes of the element node.
[0047] Step S103, determining the position information of the target character string in the text character string of the target text node, and determining the coordinate information of the target character string on the Web page according to the position information.
[0048] Optionally, the position information includes a starting index (i.e., the target string is the number of the target text node in the text string) and a length. Since the target string follows the zero-width string, the starting index of the target string in the text string of the target text node can be calculated based on the starting index of the zero-width string in the text string of the target text node and the length of the zero-width string. Since the source string corresponding to the zero-width string contains the length of the target string, the zero-width string is reversed to obtain the length of the target string. Then, based on the starting index and length of the target string, the coordinate information of the target string on the Web page can be determined.
[0049] Step S104: displaying the target character string in the visible area of the Web page according to the coordinate information of the target character string on the Web page.
[0050] Optionally, the target string can be displayed in the visible area of the Web page according to the coordinate information of the target string in the Web page. For example, according to the coordinate information of the target string in the Web page, the position of the scroll bar can be adjusted to display the target string in the visible area of the Web page.
[0051] Based on the scheme defined by the above steps S101 to S104, it can be known that in an embodiment of the present invention, a method of setting an anchor point using a zero-width character is adopted. First, a click operation of a target object on a target positioning component in a Web page is responded to, and preset id information and a preset zero-width character string corresponding to the target positioning component are obtained. Then, a target text node is determined based on the preset id information and the preset zero-width character string, wherein the text string of the target text node contains a target character string to be located, and a zero-width character string that is the same as the preset zero-width character string. Then, the position information of the target character string in the text string of the target text node is determined, and the coordinate information of the target character string on the Web page is determined based on the position information. Then, based on the coordinate information of the target character string on the Web page, the target character string is displayed in a visible area of the Web page.
[0052] It is easy to notice that in the above process, by using zero-width character encoding technology to set anchor points in text nodes, the target text node can be determined based on preset ID information and preset zero-width character strings, so that the target character string can be displayed in the visible area of the Web page, and each character in the Web page can be accurately located without changing the page hierarchy, giving users a better interactive experience.
[0053] It can be seen that through the technical solution of the present invention, the purpose of realizing rapid positioning with accuracy to a specific character string is achieved without changing the structure of the original HTML of the Web page and the page loading speed, thereby achieving the technical effect of improving the accuracy of rapid positioning within the page from the element node level to the character level without affecting the original DOM structure of the page and the loading speed of the page, thereby solving the technical problem in the prior art of using character wrapping tags to achieve target character positioning of the Web page, which has a complex code structure and leads to a low page loading speed.
[0054] In an optional embodiment, a target text node is determined based on preset id information and a preset zero-width character string, including: based on the preset id information, determining a target element node in a DOM tree corresponding to a web page, wherein the target element node is an element node having an id attribute that is the same as the preset id information; based on the preset zero-width character string, determining a target text node from a plurality of child nodes of the target element node.
[0055] In an optional embodiment, a target text node is determined from multiple child nodes of a target element node based on a preset zero-width string, including: comparing the preset zero-width string with the text string stored in the node attributes of each child node respectively; and taking the child node whose text string contains the same zero-width string as the preset zero-width string as the target text node.
[0056] Optionally, in the process of determining the target text node based on preset id information and a preset zero-width string, the target element node is first determined in the DOM tree corresponding to the web page based on the preset id information. For example, the element node that directly wraps the target string is found based on a specific id (i.e., the preset id number), and then the target text node is determined from multiple child nodes of the target element node based on the preset zero-width string.
[0057] An element node has multiple child nodes, among which a text node has a textContent attribute that stores the string associated with the node. By traversing these text nodes and comparing the strings, the only text node that meets the conditions can be filtered out. Therefore, in the process of determining the target text node from the multiple child nodes of the target element node based on the preset zero-width string, the preset zero-width string is compared with the text string stored in the node attribute of each child node, and then the child node whose text string contains the zero-width string that is the same as the preset zero-width string is used as the target text node.
[0058] It should be noted that by using zero-width character encoding technology to set anchor points in text nodes, the target text node can be determined based on preset ID information and preset zero-width character strings, thereby accurately locating each character in the Web page without changing the page hierarchy.
[0059] In an optional embodiment, determining the position information of a target string in a text string of a target text node includes: determining the index information of the target string in the text string of the target text node based on the index information of a zero-width string that is the same as a preset zero-width string in the text string of the target text node and the length information of the zero-width string; performing a reverse encoding and parsing process on the zero-width string to obtain the length information of the target string; and composing the position information based on the index information of the target string in the text string of the target text node and the length information of the target string.
[0060] Optionally, the index information of the target string in the text string of the target text node can be determined based on the index information of the zero-width string that is the same as the preset zero-width string in the text string of the target text node and the length information of the zero-width string. Since the target string immediately follows the zero-width string, the starting index of the target string in the text string of the target text node can be calculated based on the starting index of the zero-width string in the text string of the target text node and the length of the zero-width string to obtain the index information.
[0061] Optionally, since the source string corresponding to the zero-width string contains the length of the target string, the zero-width string can be de-encoded and parsed to obtain the length information of the target string, and then the position information is composed based on the index information of the target string in the text string of the target text node and the length information of the target string.
[0062] In some examples, the length of the target string is parsed by de-encoding the zero-width string. De-encoding the zero-width string is the reverse process of zero-width string encoding, which mainly includes the following steps: splitting a specific zero-width string into multiple sub-zero-width strings with ";" as the delimiter; for each sub-zero-width string, replacing ";" with "0" and replacing ";" with "1", and restoring it to a binary string containing only "0" and "1"; converting each binary string into UTF_8 characters; concatenating all characters and converting them into the pattern of ${id}_${index}_${offset} to obtain the source string. Through the de-encoding process, the offset, that is, the length of the target string, can be parsed.
[0063] In an optional embodiment, the target string is displayed in a visible area of the Web page according to coordinate information of the target string in the Web page, including: determining a rectangular area corresponding to the target string in the Web page according to the coordinate information; determining a positional relationship between the rectangular area and the visible area, and determining a target offset of the scroll bar based on the positional relationship and current position information of a scroll bar of the Web page; and adjusting the position of the scroll bar according to the target offset to display the target string in the visible area of the Web page.
[0064] In some examples, by constructing a Range object and setting the coordinates (starting position and ending position) of the Range object, the text range in the document can be specified to obtain the coordinates of the target string on the Web page, where the starting position is the starting index of the target string and the ending position is the starting index of the target string plus the length of the target string. Then, the target offset of the scroll bar can be calculated based on the coordinates of the Range object, and the scroll offset of the scroll bar can be modified to make the target string appear in the visible area.
[0065] In a web page, the default pixel coordinate system is a rectangular coordinate system with the upper left corner of the browser as the origin, the right as the positive direction of the X axis, and the downward as the positive direction of the Y axis. The Range objects constructed by the element nodes, text nodes, and target strings in the page all occupy a rectangular area, and their coordinates refer to the coordinates of the pixels in the upper left corner of the rectangular area. Figure 2 is a schematic diagram of the state of a page element in an optional Web page according to an embodiment of the present invention. Optionally, vertical scrolling is taken as an example (the positioning principle in the horizontal direction is similar), and the visible area ( Figure 2 The top of the area corresponding to the scroll bar in the middle is the baseline. There are two states of the page elements before scrolling: Figure 2 As shown on the left, the rectangular area (i.e., Range area) corresponding to the target string before scrolling is above the baseline; Figure 2 As shown on the right, the rectangular area corresponding to the target string is below the baseline before scrolling.
[0066] The scroll bar is adjusted to make the Range object appear at the beginning of the visible area, such as Figure 2 As shown, offsetY2 is the target offset of the scroll bar to make the logo character appear in the visible area; offsetY1 is the offset of the current scroll bar; y is the y-axis coordinate of the target string, Figure 2 In the left side, y is a negative number. Combining the two cases, we can know that offsetY2 = offsetY1 + y.
[0067] Figure 3 FIG. 1 is a schematic diagram of an optional process of using zero-width characters to set an anchor point for precise positioning within a page according to an embodiment of the present invention. Figure 3 As shown, it mainly includes setting anchor points and quick positioning. Among them, setting anchor points is to mark the content that needs to be quickly positioned in the original web page, that is, the target string; quick positioning is to scroll the target string into the visible area.
[0068] Optionally, the steps of setting the anchor point are as follows: setting an id attribute for a tag that directly wraps the target string; and inserting a zero-width string before the target string.
[0069] Optionally, the steps for quick positioning are as follows: find the element node that directly wraps the target string according to a specific ID; find the text node that contains a specific zero-width string; calculate the starting index of the target string in the text node string; calculate the length of the target string; construct a Range object and set the starting position and end position of the Range; calculate the target offset of the scroll bar; modify the scroll offset of the scroll bar so that the target string appears in the visible area.
[0070] In an embodiment of the present invention, a method of setting an anchor point by using a zero-width character is adopted. First, a click operation of a target object on a target positioning component in a Web page is responded to, preset ID information and a preset zero-width character string corresponding to the target positioning component are obtained, and then a target text node is determined based on the preset ID information and the preset zero-width character string, wherein the text string of the target text node contains a target character string to be located and a zero-width character string that is the same as the preset zero-width character string, and then the position information of the target character string in the text string of the target text node is determined, and the coordinate information of the target character string on the Web page is determined based on the position information, and then the target character string is displayed in a visible area of the Web page based on the coordinate information of the target character string on the Web page.
[0071] In the above process, the zero-width character encoding technology is used to set the anchor point in the text node, and the target text node can be determined according to the preset ID information and the preset zero-width character string, so that the target character string can be displayed in the visible area of the Web page, and each character in the Web page can be accurately located without changing the page hierarchy structure, giving users a better interactive experience.
[0072] It can be seen that through the technical solution of the present invention, the purpose of realizing rapid positioning with accuracy to a specific character string is achieved without changing the structure of the original HTML of the Web page and the page loading speed, thereby achieving the technical effect of improving the accuracy of rapid positioning within the page from the element node level to the character level without affecting the original DOM structure of the page and the loading speed of the page, thereby solving the technical problem in the prior art of using character wrapping tags to achieve target character positioning of the Web page, which has a complex code structure and leads to a low page loading speed.
[0073] Example 2
[0074] According to an embodiment of the present invention, an embodiment of a device for locating page content is provided, wherein: Figure 4 is a schematic diagram of an optional device for locating page content according to an embodiment of the present invention, such as Figure 4 As shown, the device includes: an acquisition module 401, which is used to respond to the target object's click operation on the target positioning component in the Web page, and obtain the preset ID information and the preset zero-width character string corresponding to the target positioning component; a first determination module 402, which is used to determine the target text node according to the preset ID information and the preset zero-width character string, wherein the text string of the target text node contains the target character string to be located, and the zero-width character string that is the same as the preset zero-width character string; a second determination module 403, which is used to determine the position information of the target character string in the text string of the target text node, and determine the coordinate information of the target character string on the Web page according to the position information; a processing module 404, which is used to display the target character string in the visible area of the Web page according to the coordinate information of the target character string on the Web page.
[0075] It should be noted that the above-mentioned acquisition module 401, first determination module 402, second determination module 403 and processing module 404 correspond to steps S101 to S104 in the above-mentioned embodiment, and the examples and application scenarios implemented by the four modules and the corresponding steps are the same, but are not limited to the contents disclosed in the above-mentioned embodiment 1.
[0076] Optionally, the first determination module includes: a first determination unit, used to determine the target element node in the DOM tree corresponding to the web page based on preset id information, wherein the target element node is an element node having an id attribute identical to the preset id information; and a second determination unit, used to determine the target text node from multiple child nodes of the target element node based on a preset zero-width character string.
[0077] Optionally, the second determination unit includes: a comparison submodule, used to compare the preset zero-width string with the text string stored in the node attributes of each child node respectively; and a determination submodule, used to take the child node whose text string contains the same zero-width string as the preset zero-width string as the target text node.
[0078] Optionally, the second determination module includes: a third determination unit, used to determine the index information of the target string in the text string of the target text node based on the index information of a zero-width string identical to a preset zero-width string in the text string of the target text node and the length information of the zero-width string; a first processing unit, used to perform de-encoding and parsing processing on the zero-width string to obtain the length information of the target string; and a second processing unit, used to compose position information based on the index information of the target string in the text string of the target text node and the length information of the target string.
[0079] Optionally, the processing module includes: a fourth determination unit, used to determine the rectangular area corresponding to the target character string in the Web page based on the coordinate information; a fifth determination unit, used to determine the positional relationship between the rectangular area and the visible area, and determine the target offset of the scroll bar based on the positional relationship and the current position information of the scroll bar of the Web page; and a third processing unit, used to adjust the position of the scroll bar based on the target offset to display the target character string in the visible area of the Web page.
[0080] Optionally, the page content locating device also includes: a configuration module, which is used to configure the id attribute of the tag where the target string is located based on preset id information in the HTML file corresponding to the Web page before responding to the target object's click operation on the target locating component in the Web page, and insert a preset zero-width string before the target string to achieve anchor point setting for the Web page.
[0081] Optionally, the page content positioning device also includes the following modules, which are used to obtain a preset zero-width string through the following steps: a construction module, which is used to construct a source string based on the id attribute of the tag where the target string is located, the index of the target string under the current element node, and the length of the target string; a first conversion module, which is used to convert each character in the source string into a binary string to obtain multiple binary strings corresponding to the source string; a second conversion module, which is used to replace the first number in the binary string based on the first zero-width character, and replace the second number in the binary string based on the second zero-width character for each binary string, to obtain a zero-width string corresponding to each binary string; and a connection module, which is used to connect the zero-width strings corresponding to each binary string based on the third zero-width character to obtain a preset zero-width string.
[0082] Example 3
[0083] According to another aspect of an embodiment of the present invention, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the computer program implements the above-mentioned method for locating page content.
[0084] Example 4
[0085] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the above-mentioned method for locating page content when running.
[0086] Example 5
[0087] According to another aspect of an embodiment of the present invention, there is also provided an electronic device, wherein: Figure 5 is a schematic diagram of an optional electronic device according to an embodiment of the present invention, such as Figure 5 As shown, the electronic device includes one or more processors; a memory for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors are implemented to run the programs, wherein the programs are set to execute the above-mentioned method for locating the page content when running. When the processor executes the program, the following steps are implemented: in response to the target object's click operation on the target positioning component in the Web page, the preset ID information and the preset zero-width string corresponding to the target positioning component are obtained; the target text node is determined according to the preset ID information and the preset zero-width string, wherein the text string of the target text node contains the target string to be located, and the zero-width string that is the same as the preset zero-width string; the position information of the target string in the text string of the target text node is determined, and the coordinate information of the target string in the Web page is determined according to the position information; according to the coordinate information of the target string in the Web page, the target string is displayed in the visible area of the Web page.
[0088] Optionally, when the processor executes the program, the following steps are also implemented: based on preset id information, determining the target element node in the DOM tree corresponding to the web page, wherein the target element node is an element node having an id attribute that is the same as the preset id information; based on a preset zero-width character string, determining the target text node from multiple child nodes of the target element node.
[0089] Optionally, when executing the program, the processor further implements the following steps: comparing the preset zero-width string with the text string stored in the node attribute of each child node respectively; and taking the child node whose text string contains the same zero-width string as the preset zero-width string as the target text node.
[0090] Optionally, when executing the program, the processor also implements the following steps: determining the index information of the target string in the text string of the target text node based on the index information of a zero-width string identical to a preset zero-width string in the text string of the target text node and the length information of the zero-width string; performing de-encoding and parsing processing on the zero-width string to obtain the length information of the target string; and composing position information based on the index information of the target string in the text string of the target text node and the length information of the target string.
[0091] Optionally, when the processor executes the program, the following steps are also implemented: determining the rectangular area corresponding to the target character string in the Web page based on the coordinate information; determining the positional relationship between the rectangular area and the visible area, and determining the target offset of the scroll bar based on the positional relationship and the current position information of the scroll bar of the Web page; adjusting the position of the scroll bar based on the target offset to display the target character string in the visible area of the Web page.
[0092] Optionally, the processor also implements the following steps when executing the program: before responding to the target object's click operation on the target positioning component in the Web page, in the HTML file corresponding to the Web page, the id attribute of the tag where the target string is located is configured based on preset id information, and a preset zero-width string is inserted before the target string to achieve anchor point setting for the Web page.
[0093] Optionally, the processor also implements the following steps when executing the program: construct a source string based on the id attribute of the tag where the target string is located, the index of the target string under the current element node, and the length of the target string; convert each character in the source string into a binary string to obtain multiple binary strings corresponding to the source string; for each binary string, replace the first number in the binary string based on the first zero-width character, and replace the second number in the binary string based on the second zero-width character to obtain a zero-width string corresponding to each binary string; and connect the zero-width strings corresponding to each binary string based on the third zero-width character to obtain a preset zero-width string.
[0094] The devices in this article can be servers, PCs, PADs, mobile phones, etc.
[0095] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0096] In the above embodiments of the present invention, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0097] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units can be a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0098] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0099] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0100] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program codes.
[0101] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A method for locating page content, It is characterized in that include: In response to a click operation of a target object on a target positioning component in a Web page, obtaining preset ID information and a preset zero-width string corresponding to the target positioning component; Determine a target text node according to the preset ID information and the preset zero-width character string, wherein the text character string of the target text node includes a target character string to be located and a zero-width character string that is the same as the preset zero-width character string; Determine the position information of the target character string in the text character string of the target text node, and determine the coordinate information of the target character string on the Web page according to the position information; The target character string is displayed in a visible area of the Web page according to the coordinate information of the target character string on the Web page.
2. The method according to claim 1, It is characterized in that Determining a target text node according to the preset ID information and the preset zero-width character string includes: According to the preset id information, determine a target element node in the DOM tree corresponding to the Web page, wherein the target element node is an element node having an id attribute identical to the preset id information; The target text node is determined from a plurality of child nodes of the target element node according to the preset zero-width character string.
3. The method according to claim 2, It is characterized in that Determining the target text node from a plurality of child nodes of the target element node according to the preset zero-width character string includes: Comparing the preset zero-width character string with the text character string stored in the node attribute of each child node respectively; The child node of the text string containing the zero-width string identical to the preset zero-width string is taken as the target text node.
4. The method according to any one of claims 1 to 3, It is characterized in that Determining the position information of the target character string in the text character string of the target text node includes: Determine the index information of the target string in the text string of the target text node according to the index information of the zero-width string identical to the preset zero-width string in the text string of the target text node and the length information of the zero-width string; Performing reverse encoding and parsing processing on the zero-width character string to obtain length information of the target character string; The position information is composed according to the index information of the target character string in the text character string of the target text node and the length information of the target character string.
5. The method according to any one of claims 1 to 3, It is characterized in that Displaying the target character string in a visible area of the Web page according to the coordinate information of the target character string on the Web page includes: Determining a rectangular area corresponding to the target character string in the Web page according to the coordinate information; Determining a positional relationship between the rectangular area and the visible area, and determining a target offset of the scroll bar based on the positional relationship and current position information of the scroll bar of the Web page; The position of the scroll bar is adjusted according to the target offset to display the target character string in the visible area of the Web page.
6. The method according to any one of claims 1 to 3, It is characterized in that Before responding to the target object's click operation on the target positioning component in the Web page, the method further includes: In the HTML file corresponding to the Web page, the id attribute of the tag where the target string is located is configured based on the preset id information, and the preset zero-width string is inserted before the target string to achieve anchor point setting for the Web page.
7. The method according to claim 6, It is characterized in that The preset zero-width string is obtained by following the steps below: Construct a source string according to the id attribute of the tag where the target string is located, the index of the target string under the current element node, and the length of the target string; Convert each character in the source string into a binary string to obtain multiple binary strings corresponding to the source string; For each binary string, replace a first number in the binary string based on a first zero-width character, and replace a second number in the binary string based on a second zero-width character, to obtain a zero-width string corresponding to each binary string; The zero-width character string corresponding to each binary character string is connected according to the third zero-width character to obtain the preset zero-width character string.
8. A device for locating page content, It is characterized in that include: An acquisition module, used for responding to a click operation of a target object on a target positioning component in a Web page, and acquiring preset ID information and a preset zero-width string corresponding to the target positioning component; A first determination module is used to determine a target text node according to the preset ID information and the preset zero-width character string, wherein the text character string of the target text node includes a target character string to be located and a zero-width character string that is the same as the preset zero-width character string; A second determination module is used to determine the position information of the target character string in the text character string of the target text node, and determine the coordinate information of the target character string in the Web page according to the position information; The processing module is used to display the target character string in the visible area of the Web page according to the coordinate information of the target character string on the Web page.
9. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, wherein the computer program is configured to execute the method for locating page content as claimed in any one of claims 1 to 7 when running.
10. An electronic device, It is characterized in that The electronic device includes one or more processors; A memory for storing one or more programs, which, when executed by the one or more processors, enables the one or more processors to run the programs, wherein the program is configured to execute the method for locating page content described in any one of claims 1 to 7 when running.
