A method for locating web page label text
By inserting event monitors into the webpage DOM tree and searching for valid text information, the problem of difficulty in obtaining control semantic information in the RPA process is solved, automatic positioning and label extraction are realized, the readability and accuracy of the process are improved, and the process is simplified. Control operations.
Patent Information
- Application Number
- CN202111346359.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-15
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2041-11-15
AI Technical Summary
With existing technology, it is difficult to directly obtain the semantic information of web page controls in the RPA process, making it difficult to locate and understand control operations. In particular, the list of controls such as edit boxes and selection boxes has unclear positions on the page, affecting the readability and execution of the process. .
By inserting an event monitor into the webpage DOM tree, it responds to user operations, locates the current operation control and finds nodes containing valid text information, uses tag information to locate and send, and combines the characteristics of the webpage DOM tree and the control position rules to achieve automatic Positioning and tag extraction.
It provides a more understandable control label representation, improves the readability and accuracy of the RPA process, reduces the complexity of manual positioning, has a small amount of calculation and high accuracy, and has advantages over other methods such as template matching and CV identification.
Smart Images

Figure CN114020576B
Abstract
Description
Technical Field
[0001] The invention relates to a web page label text positioning method, belonging to the technical field of web page label positioning. Background Art
[0002] Each operation in the RPA process includes two aspects, namely, locating the control and performing the corresponding operation. For web page controls, they can generally be located through xpath or cssselector. Since xpath or cssselector only contains the location information of the control, but not the semantic information of the control, although it can be used for accurate positioning, it is not convenient for people to understand. Therefore, when designing a web page, text labels are generally used to represent the semantic information of the control. When users operate the page, they locate and operate the corresponding control according to the label. This text label and the control that is actually operated are two controls, which are adjacent in position.
[0003] For web page controls, the button label is generally placed inside the button node and can be directly extracted. However, the list of controls such as edit boxes and selection boxes is often outside the control node. They are adjacent in the absolute position of the page, but there is no clear relationship in the DOM tree of the web page, which makes it inconvenient to directly obtain. If there is no label to represent semantics, only the positioning information of the control is used to represent the control. Although the RPA process can be executed correctly, it will be difficult for people to understand these processes. It is often necessary to manually reposition these controls on the page to find their corresponding semantic information. Since there may be a lot of operations in a process, the whole process is very troublesome. When users read the RPA process, if they want to know the meaning of these controls, they need to manually reposition them, which is very inconvenient. Summary of the invention
[0004] The purpose of the present invention is to overcome the deficiencies in the prior art and provide a web page label text positioning method that can automatically position web page labels and obtain label text corresponding to controls.
[0005] To achieve the above object, the present invention is implemented by adopting the following technical solutions:
[0006] In a first aspect, the present invention provides a method for locating web page tag text, comprising:
[0007] In response to a web page event generated by a user operating the web page, an event monitor is inserted into the web page DOM tree;
[0008] In response to a user operating a web page control, the node where the currently operated control is located is located in the web page DOM tree;
[0009] Find the node containing valid text information based on the node where the current operation control is located;
[0010] In response to finding a node containing valid text information, the node information and label are sent to a specified location.
[0011] Furthermore, the criterion for determining the valid text information is that the number of Chinese characters does not exceed ten, and there are no other non-text character strings between the characters.
[0012] Furthermore, based on the node where the current operation control is located, a node containing valid text information is searched, including:
[0013] Get the sequence number N of the node where the current operation control is located at the current level;
[0014] Node search based on the value of sequence number N includes:
[0015] In response to the sequence number N being greater than zero, obtaining a node with a sequence number of N-1 at the same level;
[0016] In response to the sequence number N being zero, obtaining the parent node of the node where the current operation control is located;
[0017] Based on the parent node of the node where the current operation control is located, obtain the level number N of the parent node at the previous level, and repeat the node search process;
[0018] In response to a node not containing valid text information, skip the node and continue searching forward;
[0019] In response to finding a node containing valid text information, the search ends.
[0020] Furthermore, based on the node where the current operation control is located, a node containing valid text information is searched, including:
[0021] Get the sequence number N and position of the node where the current operation control is located in the current level;
[0022] Node search based on the value of sequence number N includes:
[0023] In response to the sequence number N being greater than zero, obtaining a node with a sequence number of N-1 at the same level;
[0024] In response to the sequence number N being zero, obtaining the parent node of the node where the current operation control is located;
[0025] Based on the parent node of the node where the current operation control is located, obtain the level number N of the parent node at the previous level, and repeat the node search process;
[0026] In response to a node not containing valid text information, skip the node and continue searching forward;
[0027] In response to finding a node containing valid text information, the valid text information corresponding to the node and the absolute position of the node in the page are recorded;
[0028] In response to the number of nodes containing valid text information having been found reaching a specified number of nodes, the search is terminated;
[0029] Selects the first matching node based on its absolute position on the page.
[0030] Furthermore, the number of the designated nodes is no more than five.
[0031] Furthermore, the first matching node is selected based on the absolute position of the node on the page, including: determining whether there is a corresponding node containing valid text information on the left side of the control, and if so, returning the node with the largest overlapping area; otherwise, determining whether there is a corresponding node containing valid text information above the control, and if so, returning the node with the largest overlapping area, otherwise returning empty.
[0032] Furthermore, the text information is sent in the form of a message packet, and the message packet also includes an operation type, a control path, and a timestamp.
[0033] Furthermore, the designated location includes a backend server, a file location, and a cache address.
[0034] In a second aspect, a web page tag text positioning device includes a processor and a storage medium;
[0035] The storage medium is used to store instructions;
[0036] The processor is used to operate according to the instructions to execute the steps of any of the methods described above.
[0037] In a third aspect, a computer-readable storage medium stores a computer program, which implements the steps of any of the above methods when executed by a processor.
[0038] Compared with the prior art, the present invention has the following beneficial effects:
[0039] 1. The present invention provides a method for locating web page control labels, using labels to represent controls. Compared with the path of the control itself, labels provide more semantic information, so they are easier to understand. When creating an RPA process, labels can be used to represent the specific meaning of each operation. While ensuring the correct execution of the RPA process, the nodes represented by the labels make the entire process very easy to understand.
[0040] Second, the present invention uses the rule that labels are generally located on the left and top of controls, as well as the characteristics of the web page DOM tree, to provide a simple and effective method that obtains relatively accurate results with minimal computation. Compared with other methods such as template matching and CV recognition, its computational complexity is minimal, and the accuracy rate is not much different, achieving a good balance. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] The present invention will be further described below with reference to the accompanying drawings and embodiments, wherein:
[0042] Figure 1 Schematic diagram of the system framework of the web page tag text positioning method provided by the first embodiment of the present invention;
[0043] Figure 2 This is a schematic diagram of a browser interface of the web page tag text locating method provided in the first embodiment of the present invention;
[0044] Figure 3 This is a schematic diagram of a DOM tree of a web page tag text locating method provided in the first embodiment of the present invention;
[0045] Figure 4 Schematic diagram of label nodes of the web page label text positioning method provided in the first embodiment of the present invention;
[0046] Figure 5 This is a schematic diagram of the flow of the web page tag text positioning method provided by the first embodiment of the present invention;
[0047] Figure 5a It is a schematic diagram of the flow of a method for searching for web page tag nodes provided in the first embodiment of the present invention;
[0048] Figure 5b It is a schematic diagram of the flow of a method for searching for web page tag nodes provided in the second embodiment of the present invention; DETAILED DESCRIPTION
[0049] The present invention will be further described below in conjunction with the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solution of the present invention, and cannot be used to limit the protection scope of the present invention.
[0050] Embodiment 1:
[0051] A web page label text positioning method, the operation scenario of the method is as follows Figure 1 As shown, the scenario includes a user and an electronic device, wherein the electronic device may be a terminal with display shielding, such as a desktop computer, a notebook computer, a tablet computer, a mobile phone, a vehicle-mounted terminal, etc. The user may use the browser of the electronic device to open a web page and perform operations on the web page. Figure 2This is an example of a browser interface. In a typical web page, there are elements such as labels, edit boxes, buttons, etc. In general, the labels are on the left and right of the edit box, indicating the content to be entered in the edit box. Figure 3 This is a DOM tree diagram, which represents the internal data of a web page. In a typical web page, there are head and body nodes. The head node stores general information of the web page, such as the title, web page size, imported JS libraries, etc. The body node contains multiple levels of child nodes, corresponding to the content of the web page. Figure 4 This is a schematic diagram of a tag node, which indicates the relative distance between a tag node and the corresponding edit box in the DOM tree. They are generally not in the same level of nodes. This method takes the case of a user installing a browser plug-in in the Chrome browser as an example. Figure 5 , including the following steps:
[0052] S100: In response to a web page event generated by a user operating a web page, the browser plug-in automatically inserts an event monitor into the page DOM tree to monitor common operation events: such as click, submit, etc.;
[0053] S200: In response to a user operating a web page control, locating a node position where the currently operated control is located in the web page DOM tree;
[0054] S300: Based on the node where the current operation control is located, find the corresponding node containing valid text information (wherein the judgment standard of valid text information is that the number of Chinese characters does not exceed ten, and there is no other non-text string between the characters), refer to Figure 5a ,include:
[0055] S301: Locate the clicked button on the DOM tree, obtain the serial number N of the current level where the current operation control is located (each node can contain multiple child nodes, and the serial number starts from zero), and execute S302;
[0056] S302: Determine whether the current sequence number N is greater than zero, if it is greater than zero, execute S303, otherwise execute S307;
[0057] S303: Obtain the node with the same level number N-1, and execute S304;
[0058] S304: Determine whether the node with the level number N-1 is a corresponding node containing valid text information. If the node with the level number N-1 is a corresponding node containing valid text information, execute S305; otherwise, execute S306;
[0059] S305: Return to the node;
[0060] S306: re-execute S302 based on the node with the level number N-1 as the node with the level number N;
[0061] S307: Find the parent node of the node where the current operation control is located, obtain its level number N, and execute S308;
[0062] S308: Determine whether the parent node is a root node. If it is a root node, execute S309. Otherwise, based on the level number N of the parent node, re-execute S302.
[0063] S309: Returns empty.
[0064] It should be noted that the label of the text box is usually on the left or above it, so we search forward on the DOM tree. Forward means the node with a smaller sequence number than it (its parent node, parent parent node, etc.). , <select> <option>, <script>三种类型结点,ul.li和select.option用于表示菜单列表,它们不会是标签;script表示脚本结点,也不可能是标签。
[0065] S400:响应于查找到包含有效文本信息的结点后,将结点信息及标签(操作类型,控件路径xpath,标签,时间戳)发送给指定位置(如后台服务器、文件位置和缓存地址)。
[0066] 实施例二:
[0067] 上述实施例一是最简方案,可以达到80%准确率。为了进一步提高准确率,实施例一中的S300可以做一些加强,请参阅图5b,改进后的S300包括:
[0068] S301:在DOM树上定位按钮,获得它在DOM树的位置即在当前节点层级序号N,以及其在页面上的绝对位置(包括x,y,w,h,其中x,y为控件的左上角坐标,w,h分别表示控件的宽和高),执行S302;
[0069] S302:判断当前序号N是否大于零,若大于零则执行S303,否则执行S307;
[0070] S303:获取同一层级序号为N-1的结点,及其绝对位置,执行S304;
[0071] S304:判断该层级序号为N-1的结点是否为包含有效文本信息的对应结点,若该层级序号为N-1的结点为包含有效文本信息的对应结点则执行S305,否则执行S306;
[0072] S305:判断包含有效文本信息的对应结点数量是否达标,若达标则执行S309,否则执行S306;
[0073] S306:基于该层级序号为N-1的结点作为层级序号为N的结点,重新执行S302;
[0074] S307:寻找当前操作控件所在结点的父结点,获取其层级序号N,执行S308;
[0075] S308:判断该父节点是否为根节点,若非根节点则基于该父结点的层级序号N,重新执行S302,若是根节点则执行S309;
[0076] S309:判断控件左边是否存在包含有效文本信息的对应结点,若存在则执行S310,否则执行S311;
[0077] S310:返回重叠面积最大的结点;
[0078] S311:判断控件上边是否存在包含有效文本信息的对应结点,若存在则执行S312,否则执行S313;
[0079] S312:返回重叠面积最大的结点;
[0080] S313:返回空。
[0081] 其中,S305中包含有效文本信息的对应结点数量标准最多为五个包含有效文本信息的结点。
[0082] 实施例三:
[0083] 本发明实施例还提供了一种网页标签文本定位装置,包括处理器及存储介质;
[0084] 所述存储介质用于存储指令;
[0085] 所述处理器用于根据所述指令进行操作以执行下述方法的步骤:
[0086] 响应于用户操作网页产生网页事件时,向网页DOM树中插入事件监控器;
[0087] 响应于用户操作网页控件时,于网页DOM树中定位当前操作控件所在结点;
[0088] 基于当前操作控件所在结点查找包含有效文本信息的结点;
[0089] 响应于查找到包含有效文本信息的结点后,将结点信息及标签发送至指定位置。
[0090] 实施例四:
[0091] 本发明实施例还提供了一种计算机可读存储介质,其上存储有计算机程序,该程序被处理器执行时实现下述方法的步骤:
[0092] 响应于用户操作网页产生网页事件时,向网页DOM树中插入事件监控器;
[0093] 响应于用户操作网页控件时,于网页DOM树中定位当前操作控件所在结点;
[0094] 基于当前操作控件所在结点查找包含有效文本信息的结点;
[0095] 响应于查找到包含有效文本信息的结点后,将结点信息及标签发送至指定位置。
[0096] 本领域内的技术人员应明白,本申请的实施例可提供为方法、系统、或计算机程序产品。因此,本申请可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本申请可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。
[0097] 本申请是参照根据本申请实施例的方法、设备(系统)、和计算机程序产品的流程图和 / 或方框图来描述的。应理解可由计算机程序指令实现流程图和 / 或方框图中的每一流程和 / 或方框、以及流程图和 / 或方框图中的流程和 / 或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和 / 或方框图一个方框或多个方框中指定的功能的装置。
[0098] 这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和 / 或方框图一个方框或多个方框中指定的功能。
[0099] 这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和 / 或方框图一个方框或多个方框中指定的功能的步骤。
[0100] 以上所述仅是本发明的优选实施方式,应当指出,对于本技术领域的普通技术人员来说,在不脱离本发明技术原理的前提下,还可以做出若干改进和变形,这些改进和变形也应视为本发明的保护范围。< / script> < / option> < / select>
Claims
1. A web page tag text positioning method, characterized in that: include: When a webpage event is generated in response to a user operating the webpage, an event monitor is inserted into the webpage DOM tree; In response to a user operating a web page control, the node where the currently operated control is located is located in the web page DOM tree; Search for a node containing valid text information based on the node where the current operation control is located; In response to finding a node containing valid text information, the node information and label are sent to a designated location; Search for nodes containing valid text information based on the node where the current operation control is located, including: Get the sequence number N of the node where the current operation control is located in the current level; Node search based on the value of sequence number N includes: In response to the sequence number N being greater than zero, obtaining the node with the sequence number N-1 of the same level node; In response to the sequence number N being zero, obtaining the parent node of the node where the current operation control is located; Based on the parent node of the node where the current operation control is located, obtain the hierarchical sequence number M of the parent node at the previous level and repeat the node search process; In response to a node not containing valid text information, skip the node and continue searching forward; In response to finding a node containing valid text information, ending the search; Alternatively, search for nodes containing valid text information based on the node where the current operation control is located, including: Get the sequence number N of the node where the current operation control is located in the current level and the absolute position of the node in the page; Node search based on the value of sequence number N includes: In response to the sequence number N being greater than zero, obtaining the node with the sequence number N-1 of the same level node; In response to the sequence number N being zero, obtaining the parent node of the node where the current operation control is located; Based on the parent node of the node where the current operation control is located, obtain the hierarchical sequence number M of the parent node at the previous level and repeat the node search process; In response to a node not containing valid text information, skip the node and continue searching forward; In response to finding a node containing valid text information, the valid text information corresponding to the node and the absolute position of the node in the page are recorded; In response to the number of nodes containing valid text information having been found reaching a specified number of nodes, ending the search; Select the first matching node based on the node's absolute position on the page; Select the first matching node based on the absolute position of the node on the page, including: judging whether there is a corresponding node containing valid text information on the left side of the control, and if so, returning the node with the largest overlapping area; otherwise, judging whether there is a corresponding node containing valid text information above the control, and if so, returning the node with the largest overlapping area, otherwise returning empty.
2. The web page tag text positioning method according to claim 1, characterized in that: The criteria for determining valid text information is that the number of Chinese characters does not exceed ten, and there are no other non-text character strings between the characters.
3. The web page tag text positioning method according to claim 1, characterized in that: The number of the designated nodes is no more than five.
4. The web page tag text positioning method according to claim 1, characterized in that: The text information is sent in the form of a message packet, which also includes an operation type, a control path, and a timestamp.
5. The web page tag text positioning method according to claim 1, characterized in that: The designated location includes a backend server, a file location, and a cache address.
6. A web page label text positioning device, characterized in that: including processors and storage media; The storage medium is used to store instructions; The processor is configured to operate according to the instructions to execute the steps of the method according to any one of claims 1 to 5.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
