A webpage automation method and device, computer equipment and storage medium
By combining WebDriver and browser plugins, the operation method is selected based on the number of JSON arrays containing the content of page elements. This solves the problem of low compatibility in traditional web page automation methods and achieves more efficient web page automation operations, especially on anti-scraping web pages.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- YGSOFT INC
- Filing Date
- 2023-03-21
- Publication Date
- 2026-07-07
Smart Images

Figure CN116304431B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to a web page automation method, apparatus, computer equipment, and storage medium. Background Technology
[0002] With the rapid development of internet technology, internet products are growing exponentially, with web applications experiencing particularly rapid growth. As products iterate and grow rapidly, ensuring the quality of web products becomes increasingly important. During this rapid iteration process, the workload of regression testing is increasing daily to guarantee quality. Therefore, there is an urgent need for automated web testing to replace manual testing, thereby significantly improving testing efficiency.
[0003] For web page automation functions implemented through component design applications, there is currently an implementation method based on WebDriver. However, the applicant found that WebDriver has a high technical threshold and is not friendly to novice developers. At the same time, some web pages have anti-scraping measures, which makes these web pages incompatible with WebDriver technology. It can be seen that traditional web page automation methods based on WebDriver have low compatibility issues. Summary of the Invention
[0004] The purpose of this application is to provide a web page automation method, apparatus, computer device, and storage medium to solve the problem of low compatibility in traditional web driver-based web page automation methods.
[0005] To address the aforementioned technical problems, this application provides a webpage automation method, employing the following technical solution:
[0006] Launch the target browser via WebDriver;
[0007] Launch the target browser plugin corresponding to the target browser;
[0008] Based on the target browser plugin, obtain the page element location content corresponding to the target browser;
[0009] Determine whether the content of the page element belongs to a JSON array and whether the number of the JSON array is greater than 1;
[0010] If the content of the page element is located in a JSON array and the number of elements in the JSON array is greater than 1, then the webpage will be automatically operated on the content of the page element located according to the target browser plugin.
[0011] If the content located by the page element does not belong to the JSON array, or belongs to the JSON array but the number of elements in the JSON array is equal to 1, then the webpage automation operation is performed on the content located by the page element according to the WebDriver.
[0012] Furthermore, the target browser can be Google Chrome or Sogou Browser, and the step of activating the target browser plugin corresponding to the target browser specifically includes the following steps:
[0013] If the target browser is Google Chrome, then the Google Chrome plugin is activated, wherein the communication mechanism of the Google Chrome plugin is nativeMessage;
[0014] If the target browser is the Sogou Browser, then the Sogou Browser plugin is activated, wherein the communication mechanism of the Sogou Browser plugin is WebSocket.
[0015] Furthermore, the step of obtaining the page element location content corresponding to the target browser based on the target browser plugin specifically includes the following steps:
[0016] When a user activates a selector in a component design application, the mouse positioning information in the target browser is obtained;
[0017] The location information is sent to the browser foreground and background of the target browser plugin;
[0018] Receive element content information sent by the browser's front-end and back-end to obtain the content of the page element location.
[0019] Furthermore, after the step of obtaining the page element location content corresponding to the target browser based on the target browser plugin, the following steps are also included:
[0020] If the JSON data of the content located by the page element is abnormal, then the webpage will be automatically processed according to the WebDriver.
[0021] To address the aforementioned technical problems, this application also provides a web page automation device, which employs the following technical solution:
[0022] The browser launcher module is used to launch the target browser via WebDriver;
[0023] The plugin launch module is used to launch the target browser plugin corresponding to the target browser;
[0024] The content acquisition module is used to acquire the content of page elements corresponding to the target browser based on the target browser plugin.
[0025] The JSON array judgment module is used to determine whether the content of the page element is a JSON array and whether the number of the JSON array is greater than 1.
[0026] The first automated operation module is used to perform automated web page operations on the content located by the page element according to the target browser plugin if the content located by the page element belongs to a JSON array and the number of the JSON array is greater than 1.
[0027] The second automated operation module is used to perform automated webpage operations on the content located by the page element according to the WebDriver if the content located by the page element does not belong to the JSON array or belongs to the JSON array but the number of the JSON array is equal to 1.
[0028] Furthermore, the target browser can be Google Chrome or Sogou Browser, and the plugin launch module includes:
[0029] The first plugin startup submodule is used to start the Google Chrome plugin if the target browser is the Google Chrome browser, wherein the communication mechanism of the Google Chrome plugin is nativeMessage;
[0030] The second plugin startup submodule is used to start the Sogou Browser plugin if the target browser is the Sogou Browser, wherein the communication mechanism of the Sogou Browser plugin is WebSocket.
[0031] Furthermore, the location content acquisition module includes:
[0032] The location information acquisition submodule is used to acquire the mouse location information in the target browser when the user activates the selector in the component design application;
[0033] The location information sending submodule is used to send the location information to the browser foreground and background of the target browser plugin;
[0034] The content acquisition submodule is used to receive element content information sent by the browser's front-end and back-end to obtain the content of the page element.
[0035] Furthermore, the device also includes:
[0036] The data anomaly module is used to perform automated webpage operations on the content located by the page element according to the WebDriver if the JSON data of the content located by the page element is abnormal.
[0037] To address the aforementioned technical problems, this application also provides a computer device that employs the following technical solution:
[0038] It includes a memory and a processor, wherein the memory stores computer-readable instructions, and the processor executes the computer-readable instructions to implement the steps of the web page automation method as described above.
[0039] To address the aforementioned technical problems, this application also provides a computer-readable storage medium, employing the technical solution described below:
[0040] The computer-readable storage medium stores computer-readable instructions, which, when executed by a processor, implement the steps of the web page automation method described above.
[0041] This application provides a webpage automation method, comprising: launching a target browser via WebDriver; launching a target browser plugin corresponding to the target browser; obtaining page element location content corresponding to the target browser according to the target browser plugin; determining whether the page element location content belongs to a JSON array and the number of elements in the JSON array is greater than 1; if the page element location content belongs to a JSON array and the number of elements in the JSON array is greater than 1, then performing webpage automation operations on the page element location content according to the target browser plugin; if the page element location content does not belong to the JSON array or belongs to the JSON array but the number of elements in the JSON array is equal to 1, then performing webpage automation operations on the page element location content according to WebDriver. Compared with the prior art, this application uses a combination of browser plugins and WebDriver to implement RPA. Besides utilizing the capabilities of WebDriver, such as complex XPath and CSSSelector matching syntax, it also utilizes the capabilities of plugins, such as anti-scraping capabilities. Furthermore, by calling native browser interfaces, it effectively improves execution efficiency. Attached Figure Description
[0042] To more clearly illustrate the solutions in this application, the accompanying drawings used in the description of the embodiments of this application will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0043] Figure 1 This is an exemplary system architecture diagram to which this application can be applied;
[0044] Figure 2This is a flowchart illustrating the implementation of the webpage automation method provided in Embodiment 1 of this application;
[0045] Figure 3 yes Figure 2 A flowchart of a specific implementation of step S202;
[0046] Figure 4 yes Figure 2 A flowchart of a specific implementation of step S203;
[0047] Figure 5 yes Figure 2 A flowchart of a specific implementation method following step S203;
[0048] Figure 6 This is a schematic diagram of the web page automation device provided in Embodiment 2 of this application;
[0049] Figure 7 This is a schematic diagram of the structure of one embodiment of the computer device according to this application. Detailed Implementation
[0050] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains; the terminology used herein in the specification of the application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application; the terms "comprising" and "having," and any variations thereof, in the specification, claims, and foregoing drawings of this application, are intended to cover non-exclusive inclusion. The terms "first," "second," etc., in the specification, claims, or foregoing drawings of this application are used to distinguish different objects, not to describe a particular order.
[0051] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0052] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings.
[0053] like Figure 1As shown, system architecture 100 may include terminal devices 101, 102, and 103, a network 104, and a server 105. Network 104 serves as the medium for providing communication links between terminal devices 101, 102, and 103 and server 105. Network 104 may include various connection types, such as wired or wireless communication links, or fiber optic cables, etc.
[0054] Users can use terminal devices 101, 102, and 103 to interact with server 105 via network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, and 103, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social media platform software, etc.
[0055] Terminal devices 101, 102, and 103 can be various electronic devices with displays and support web browsing, including but not limited to smartphones, tablets, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III), MP4 players (Moving Picture Experts Group Audio Layer IV), laptops, and desktop computers, etc.
[0056] Server 105 can be a server that provides various services, such as a backend server that supports the pages displayed on terminal devices 101, 102, and 103.
[0057] It should be noted that the web page automation method provided in this application embodiment is generally executed by a server / terminal device, and correspondingly, the web page automation device is generally set in the server / terminal device.
[0058] It should be understood that Figure 1 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.
[0059] Example 1
[0060] Continue to refer to Figure 2 The diagram shows the implementation flowchart of the web page automation method provided in Embodiment 1 of this application. For ease of explanation, only the parts related to this application are shown.
[0061] The above-mentioned web page automation method includes steps S201, S202, S203, S204, S205 and S206.
[0062] In step S201, the target browser is launched via WebDriver.
[0063] In step S202, the target browser plugin corresponding to the target browser is activated.
[0064] In step S203, the content of the page element location corresponding to the target browser is obtained according to the target browser plugin.
[0065] In this embodiment of the application, obtaining the content of the page element location can also be achieved by pre-caching the webDriver object and generating a unique identifier sessionId. When a subsequent request is received, as long as the same sessionId is included, the webDriver object will be retrieved from the cache and used.
[0066] In step S204, it is determined whether the content located by the page element belongs to a JSON array and whether the number of JSON arrays is greater than 1.
[0067] In step S205, if the content located on the page element belongs to a JSON array and the number of JSON arrays is greater than 1, then the web page automation operation is performed on the content located on the page element according to the target browser plugin.
[0068] In this embodiment of the application, the browser plugin is used to parse the business logic and assemble the data through the local communication application, and then send it to the browser plugin to call the browser's native API to manipulate page elements.
[0069] In step S206, if the content located by the page element does not belong to the JSON array or belongs to the JSON array but the number of JSON arrays is equal to 1, then the web page automation operation is performed on the content located by the page element according to WebDriver.
[0070] In this embodiment of the application, the webDriver method is used, and xpath is used as a positioning identifier to manipulate page elements.
[0071] In this embodiment of the application, the content generated after selecting an element by the selector is first matched to see if it belongs to a JSON array. If it is a JSON array and the number is greater than 1, it means that there is an iframe structure, and the plugin method will be used; otherwise, the webDriver method will be used.
[0072] In some optional implementations of this embodiment, the running mode can also be explicitly specified in the executeType parameter of each component.
[0073] In some optional implementations of this embodiment, when using the webDriver method, it is necessary to further parse which webDriver positioning mode the positioned content belongs to. For example, those starting with " / " or "(" are considered to be XPath mode. Otherwise, if the positioned content contains "#", "".", "[", "'", "\", "=", "", "">", "+", "(", "":"), it is considered to be a CSSSelector. Others are defaulted to ID. This can adapt to most cases. Alternatively, JSON format can be used to explicitly specify which webDriver positioning mode the positioned content belongs to.
[0074] This application provides a webpage automation method, comprising: launching a target browser via WebDriver; launching a target browser plugin corresponding to the target browser; obtaining page element location content corresponding to the target browser according to the target browser plugin; determining whether the page element location content belongs to a JSON array and the number of JSON arrays is greater than 1; if the page element location content belongs to a JSON array and the number of JSON arrays is greater than 1, then performing webpage automation operations on the page element location content according to the target browser plugin; if the page element location content does not belong to a JSON array or belongs to a JSON array but the number of JSON arrays is equal to 1, then performing webpage automation operations on the page element location content according to WebDriver. Compared with the prior art, this application uses a combination of browser plugins and WebDriver to implement RPA. In addition to using the capabilities of WebDriver, such as complex XPath and CSSSelector matching syntax, it can also use the capabilities of plugins, such as anti-scraping capabilities. Furthermore, by calling native browser interfaces, it effectively improves execution efficiency.
[0075] Continue reading Figure 3 , showed Figure 2 The flowchart of a specific implementation of step S202 is shown. For ease of explanation, only the parts relevant to this application are shown.
[0076] In some optional implementations of this embodiment, the target browser can be Google Chrome or Sogou Browser, and step S202 specifically includes step S301 or step S302.
[0077] In step S301, if the target browser is Google Chrome, the Google Chrome plugin is activated, wherein the communication mechanism of the Google Chrome plugin is nativeMessage.
[0078] In step S302, if the target browser is Sogou Browser, the Sogou Browser plugin is activated, wherein the communication mechanism of the Sogou Browser plugin is WebSocket.
[0079] In this embodiment, the front-end JavaScript of the Google Chrome plugin is responsible for executing JavaScript method blocks on specific web pages and manipulating the DOM elements of the page; the back-end JavaScript of the plugin is responsible for communicating with the local application, calling the native API interfaces of Google Chrome, and implementing cross-domain JavaScript scheduling.
[0080] In this embodiment of the application, the following selector function is achieved by developing a Google Chrome plugin based on the nativeMessage communication mechanism and combining it with a component design application.
[0081] In this embodiment of the application, since Sogou Browser does not support the nativeMessage communication mechanism, a Sogou Browser plugin based on the WebSocket communication mechanism is developed and combined with component design applications to achieve the following selector function.
[0082] In this embodiment, a local communication application is developed using Java. It communicates with the Google Chrome plugin via nativeMessage and with external systems via HTTP requests. Upon receiving an external request, it parses the business logic, assembles the data, and sends it to the Google Chrome backend JavaScript. For Sogou Browser, WebSockets are used for communication.
[0083] Continue reading Figure 4 , showed Figure 2 The flowchart of a specific embodiment of step S203 is shown. For ease of explanation, only the parts relevant to this application are shown.
[0084] In some optional implementations of this embodiment, step S203 specifically includes: step S401, step S402 and step S403.
[0085] In step S401, when the user activates the selector in the component design application, the mouse positioning information in the target browser is obtained.
[0086] In step S402, the location information is sent to the browser foreground and background of the target browser plugin.
[0087] In step S403, the element content information sent by the browser's foreground and background is received to obtain the page element location content.
[0088] In this embodiment, the selector in the component design application obtains the mouse position, passes it to the Google Chrome plugin through the local application's algorithm, thereby picking the element at the mouse position, generating a selection box as an identifier, and returning the HTML tag and XPath, which are then saved into the design flow of the component design application.
[0089] In this embodiment, users can visually select web page elements in a specified browser and easily select elements on the page for control, greatly reducing the user's learning curve.
[0090] Continue reading Figure 5 , showed Figure 2 The flowchart of a specific implementation after step S203 is shown. For ease of explanation, only the parts relevant to this application are shown.
[0091] In some optional implementations of this embodiment, after step S203, step S501 is also included.
[0092] In step S501, if the JSON data of the content located on the page element is abnormal, the webpage automation operation is performed on the content located on the page element according to WebDriver.
[0093] In this embodiment of the application, if the parsing of the element content in JSON is abnormal, it is considered to be a simple positioning pattern, and the webDriver method can still be used to locate the content of the page element for automated web page operations.
[0094] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by instructing related hardware with computer-readable instructions. These computer-readable instructions can be stored in a computer-readable storage medium, and when executed, they can include the processes of the embodiments of the methods described above. The aforementioned storage medium can be a non-volatile storage medium such as a magnetic disk, optical disk, or read-only memory (ROM), or random access memory (RAM).
[0095] It should be understood that although the steps in the flowcharts of the accompanying figures are shown sequentially as indicated by the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the accompanying figures may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.
[0096] Example 2
[0097] Further reference Figure 6 As a response to the above Figure 2The implementation of the method shown in this application provides an embodiment of a web page automation device, which is similar to... Figure 2 Corresponding to the method embodiments shown, this device can be specifically applied to various electronic devices.
[0098] like Figure 6 As shown, the webpage automation device 200 of this embodiment includes: a browser startup module 210, a plugin startup module 220, a content location acquisition module 230, a JSON array judgment module 240, a first automation operation module 250, and a second automation operation module 260. Wherein:
[0099] Browser startup module 210 is used to launch the target browser via WebDriver;
[0100] Plugin startup module 220 is used to launch the target browser plugin corresponding to the target browser.
[0101] The content acquisition module 230 is used to acquire the content of the page element corresponding to the target browser based on the target browser plugin.
[0102] Json array judgment module 240 is used to determine whether the content of a page element belongs to a JSON array and whether the number of JSON arrays is greater than 1.
[0103] The first automated operation module 250 is used to perform automated web page operations on the content located on the page element according to the target browser plugin if the content located on the page element belongs to a JSON array and the number of JSON arrays is greater than 1.
[0104] The second automated operation module 260 is used to perform automated web page operations on the content located by the page element according to WebDriver if the content located by the page element does not belong to the JSON array or belongs to the JSON array but the number of JSON arrays is equal to 1.
[0105] In this embodiment of the application, obtaining the content of the page element location can also be achieved by pre-caching the webDriver object and generating a unique identifier sessionId. When a subsequent request is received, as long as the same sessionId is included, the webDriver object will be retrieved from the cache and used.
[0106] In this embodiment of the application, the browser plugin is used to parse the business logic and assemble the data through the local communication application, and then send it to the browser plugin to call the browser's native API to manipulate page elements.
[0107] In this embodiment of the application, the webDriver method is used, and xpath is used as a positioning identifier to manipulate page elements.
[0108] In this embodiment of the application, the content generated after selecting an element by the selector is first matched to see if it belongs to a JSON array. If it is a JSON array and the number is greater than 1, it means that there is an iframe structure, and the plugin method will be used; otherwise, the webDriver method will be used.
[0109] In some optional implementations of this embodiment, the running mode can also be explicitly specified in the executeType parameter of each component.
[0110] In some optional implementations of this embodiment, when using the webDriver method, it is necessary to further parse which webDriver positioning mode the positioned content belongs to. For example, those starting with " / " or "(" are considered to be XPath mode. Otherwise, if the positioned content contains "#", "".", "[", "'", "\", "=", "", "">", "+", "(", "":"), it is considered to be a CSSSelector. Others are defaulted to ID. This can adapt to most cases. Alternatively, JSON format can be used to explicitly specify which webDriver positioning mode the positioned content belongs to.
[0111] In this embodiment, a webpage automation device 200 is provided, comprising: a browser startup module 210 for launching a target browser via WebDriver; a plugin startup module 220 for launching a target browser plugin corresponding to the target browser; a content location acquisition module 230 for acquiring the page element location content corresponding to the target browser based on the target browser plugin; a JSON array judgment module 240 for determining whether the page element location content belongs to a JSON array and the number of JSON arrays is greater than 1; a first automation operation module 250 for performing webpage automation operations on the page element location content based on the target browser plugin if the page element location content belongs to a JSON array and the number of JSON arrays is greater than 1; and a second automation operation module 260 for performing webpage automation operations on the page element location content based on WebDriver if the page element location content does not belong to a JSON array or belongs to a JSON array but the number of JSON arrays is equal to 1. Compared with existing technologies, this application uses a combination of browser plugins and webDriver to implement RPA. In addition to using the capabilities of webDriver, such as complex XPath and CSSSelector matching syntax, it can also use the capabilities of plugins, such as anti-scraping capabilities. Furthermore, by calling native browser interfaces, it effectively improves execution efficiency.
[0112] In some optional implementations of this embodiment, the above-mentioned plug-in startup module 220 includes: a first plug-in startup submodule and a second plug-in startup submodule, wherein:
[0113] The first plugin startup submodule is used to launch the Google Chrome plugin if the target browser is Google Chrome. The communication mechanism of the Google Chrome plugin is nativeMessage.
[0114] The second plugin startup submodule is used to start the Sogou Browser plugin if the target browser is Sogou Browser. The Sogou Browser plugin uses WebSocket as its communication mechanism.
[0115] In this embodiment, the front-end JavaScript of the Google Chrome plugin is responsible for executing JavaScript method blocks on specific web pages and manipulating the DOM elements of the page; the back-end JavaScript of the plugin is responsible for communicating with the local application, calling the native API interfaces of Google Chrome, and implementing cross-domain JavaScript scheduling.
[0116] In this embodiment of the application, the following selector function is achieved by developing a Google Chrome plugin based on the nativeMessage communication mechanism and combining it with a component design application.
[0117] In this embodiment of the application, since Sogou Browser does not support the nativeMessage communication mechanism, a Sogou Browser plugin based on the WebSocket communication mechanism is developed and combined with component design applications to achieve the following selector function.
[0118] In this embodiment, a local communication application is developed using Java. It communicates with the Google Chrome plugin via nativeMessage and with external systems via HTTP requests. Upon receiving an external request, it parses the business logic, assembles the data, and sends it to the Google Chrome backend JavaScript. For Sogou Browser, WebSockets are used for communication.
[0119] In some optional implementations of this embodiment, the location content acquisition module 230 includes: a location information acquisition submodule, a location information sending submodule, and a location content acquisition submodule, wherein:
[0120] The location information acquisition submodule is used to obtain the mouse location information in the target browser when the user activates the selector in the component design application;
[0121] The location information sending submodule is used to send location information to the browser foreground and background of the target browser plugin;
[0122] The content retrieval submodule is used to receive element content information sent by the browser's foreground and background to obtain the content of the page element.
[0123] In this embodiment, the selector in the component design application obtains the mouse position, passes it to the Google Chrome plugin through the local application's algorithm, thereby picking the element at the mouse position, generating a selection box as an identifier, and returning the HTML tag and XPath, which are then saved into the design flow of the component design application.
[0124] In this embodiment, users can visually select web page elements in a specified browser and easily select elements on the page for control, greatly reducing the user's learning curve.
[0125] In some optional implementations of this embodiment, the webpage automation device 100 further includes: a data anomaly module, wherein:
[0126] The data anomaly module is used to perform automated webpage operations on the located content of page elements based on WebDriver if the JSON data of the page element's location is abnormal.
[0127] In this embodiment of the application, if the parsing of the element content in JSON is abnormal, it is considered to be a simple positioning pattern, and the webDriver method can still be used to locate the content of the page element for automated web page operations.
[0128] To address the aforementioned technical problems, embodiments of this application also provide a computer device. Please refer to [link / reference needed]. Figure 7 , Figure 7 This is a basic structural block diagram of the computer device in this embodiment.
[0129] The computer device 300 includes a memory 310, a processor 320, and a network interface 330 that are interconnected via a system bus. It should be noted that only the computer device 300 with components 310-330 is shown in the figure; however, it should be understood that it is not required to implement all the shown components, and more or fewer components can be implemented alternatively. Those skilled in the art will understand that the computer device described here is a device capable of automatically performing numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes, but is not limited to, microprocessors, application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), digital signal processors (DSPs), embedded devices, etc.
[0130] The computer device can be a desktop computer, laptop, handheld computer, or cloud server, etc. The computer device can interact with the user via a keyboard, mouse, remote control, touchpad, or voice control.
[0131] The memory 310 includes at least one type of readable storage medium, including flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 310 may be an internal storage unit of the computer device 300, such as the hard disk or memory of the computer device 300. In other embodiments, the memory 310 may also be an external storage device of the computer device 300, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc. Of course, the memory 310 may also include both internal storage units and external storage devices of the computer device 300. In this embodiment, the memory 310 is typically used to store the operating system and various application software installed on the computer device 300, such as computer-readable instructions for web page automation methods. Furthermore, the memory 310 can also be used to temporarily store various types of data that have been output or will be output.
[0132] In some embodiments, the processor 320 may be a central processing unit (CPU), controller, microcontroller, microprocessor, or other data processing chip. The processor 320 is typically used to control the overall operation of the computer device 300. In this embodiment, the processor 320 is used to execute computer-readable instructions stored in the memory 310 or to process data, such as executing computer-readable instructions for the web page automation method.
[0133] The network interface 330 may include a wireless network interface or a wired network interface, which is typically used to establish communication connections between the computer device 300 and other electronic devices.
[0134] The computer device provided in this application uses a combination of browser plugins and webDriver to implement RPA. In addition to using the capabilities of webDriver, such as complex XPath and CSS Selector matching syntax, it can also use the capabilities of plugins, such as anti-scraping. Furthermore, it calls the browser's native interface, which effectively improves execution efficiency.
[0135] This application also provides another embodiment, namely, providing a computer-readable storage medium storing computer-readable instructions that can be executed by at least one processor to cause the at least one processor to perform the steps of the web page automation method described above.
[0136] The computer-readable storage medium provided in this application implements RPA by combining browser plugins and webDriver. In addition to using the capabilities of webDriver, such as complex XPath and CSSSelector matching syntax, it can also use the capabilities of plugins, such as anti-scraping measures. Furthermore, it calls native browser interfaces, effectively improving execution efficiency.
[0137] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0138] Obviously, the embodiments described above are only some embodiments of this application, not all embodiments. The accompanying drawings show preferred embodiments of this application, but do not limit the patent scope of this application. This application can be implemented in many different forms; rather, the purpose of providing these embodiments is to provide a more thorough and comprehensive understanding of the disclosure of this application. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing specific embodiments, or make equivalent substitutions for some of the technical features. Any equivalent structures made using the content of this application's specification and drawings, directly or indirectly applied to other related technical fields, are similarly within the scope of patent protection of this application.
Claims
1. A webpage automation method, characterized in that, Includes the following steps: Launch the target browser via WebDriver; Launch the target browser plugin corresponding to the target browser; Based on the target browser plugin, obtain the page element location content corresponding to the target browser; Determine whether the content of the page element belongs to a JSON array and whether the number of the JSON array is greater than 1; If the content of the page element is located in a JSON array and the number of elements in the JSON array is greater than 1, then the webpage will be automatically operated on the content of the page element located according to the target browser plugin. If the content of the page element does not belong to the JSON array, or belongs to the JSON array but the number of JSON arrays is equal to 1, then the web page automation operation is performed on the content of the page element according to the WebDriver. The target browser is Google Chrome or Sogou Browser. The step of activating the target browser plugin corresponding to the target browser specifically includes the following steps: If the target browser is Google Chrome, then the Google Chrome plugin is launched. The communication mechanism of the Google Chrome plugin is nativeMessage. The front-end JavaScript of the Google Chrome plugin is responsible for executing JavaScript method blocks on specific web pages and manipulating the DOM elements of the page. The back-end JavaScript of the Google Chrome plugin is responsible for communicating with the local application, calling the native API interface of Google Chrome, and implementing cross-domain JavaScript scheduling. If the target browser is the Sogou Browser, then the Sogou Browser plugin is activated, wherein the communication mechanism of the Sogou Browser plugin is WebSocket.
2. The webpage automation method according to claim 1, characterized in that, The step of obtaining the page element location content corresponding to the target browser based on the target browser plugin specifically includes the following steps: When a user activates a selector in a component design application, the mouse positioning information in the target browser is obtained; The location information is sent to the browser foreground and background of the target browser plugin; Receive element content information sent by the browser's front-end and back-end to obtain the content of the page element location.
3. The webpage automation method according to claim 1, characterized in that, After the step of obtaining the page element location content corresponding to the target browser based on the target browser plugin, the following steps are also included: If the JSON data of the content located by the page element is abnormal, then the webpage will be automatically processed according to the WebDriver.
4. A webpage automation device, characterized in that, include: The browser launcher module is used to launch the target browser via WebDriver; The plugin launch module is used to launch the target browser plugin corresponding to the target browser; The content acquisition module is used to acquire the content of page elements corresponding to the target browser based on the target browser plugin. The JSON array judgment module is used to determine whether the content of the page element is a JSON array and whether the number of the JSON array is greater than 1. The first automated operation module is used to perform automated web page operations on the content located by the page element according to the target browser plugin if the content located by the page element belongs to a JSON array and the number of the JSON array is greater than 1. The second automated operation module is used to perform automated web page operations on the content located by the page element according to the WebDriver if the content located by the page element does not belong to the JSON array or belongs to the JSON array but the number of the JSON array is equal to 1. The target browser is Google Chrome or Sogou Browser, and the plugin launch module includes: The first plugin startup submodule is used to start the Google Chrome plugin if the target browser is the Google Chrome. The communication mechanism of the Google Chrome plugin is nativeMessage. The front-end JS of the Google Chrome plugin is responsible for executing JS method blocks on specific web pages and manipulating the DOM elements of the page. The back-end JS of the Google Chrome plugin is responsible for communicating with the local application, calling the native API interface of Google Chrome, and implementing cross-domain JS scheduling of the page. The second plugin startup submodule is used to start the Sogou Browser plugin if the target browser is the Sogou Browser, wherein the communication mechanism of the Sogou Browser plugin is WebSocket.
5. The webpage automation device according to claim 4, characterized in that, The location content acquisition module includes: The location information acquisition submodule is used to acquire the mouse location information in the target browser when the user activates the selector in the component design application; The location information sending submodule is used to send the location information to the browser foreground and background of the target browser plugin; The content acquisition submodule is used to receive element content information sent by the browser's front-end and back-end to obtain the content of the page element.
6. The webpage automation device according to claim 4, characterized in that, The device further includes: The data anomaly module is used to perform automated webpage operations on the content located by the page element according to the WebDriver if the JSON data of the content located by the page element is abnormal.
7. A computer device, characterized in that, The device includes a memory and a processor, wherein the memory stores computer-readable instructions, and the processor executes the computer-readable instructions to implement the steps of the web page automation method as described in any one of claims 1 to 3.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-readable instructions, which, when executed by a processor, implement the steps of the web page automation method as described in any one of claims 1 to 3.