Verification code identification method and device, electronic equipment and storage medium
By obtaining the interface address of the graphical verification code in the web page automation test script, requesting and OCR recognition, the problem of low efficiency of manual input verification code in automated tests is solved, and the efficient operation of automated tests is achieved.
Patent Information
- Application Number
- CN202510606176.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-12
- Publication Date
- 2025-08-15
AI Technical Summary
In the prior art, manual judgment and verification codes are required during automated testing, resulting in inefficient testing and increased test duration.
By obtaining the interface address of the graphic verification code in the web page automation test script, performing graphic verification code requests, extracting verification code parameters and saving them as picture files, identifying them using OCR technology, and automatically filling in the verification code to complete the test.
It realizes accurate identification of verification codes during automated testing, improves testing efficiency and reduces the test time of testers.
Smart Images

Figure CN120496094A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of computer technology, and in particular to a verification code recognition method, device, electronic device, and storage medium. Background Art
[0002] With the development of technology, more and more applications or systems based on Internet browsers are being developed, such as automatic query systems. However, the applications and systems need to be fully tested and debugged before they are officially put into use.
[0003] At present, as verification code technologies on Internet browsers become more and more numerous and complex, testers need to make manual judgments and repeatedly enter verification codes before they can continue to perform tests when doing automated testing.
[0004] However, this method of manually reading and filling in the verification code is time-consuming and labor-intensive, which reduces the test efficiency and increases the test time for the tester. Summary of the Invention
[0005] The embodiments of the present invention provide a verification code recognition method, device, electronic device and storage medium to accurately and conveniently identify the text recognition results of the verification code during the automated testing process, thereby improving the testing efficiency and reducing the testing time for the tester.
[0006] In a first aspect, an embodiment of the present invention provides a verification code recognition method, comprising:
[0007] When executing the webpage automated test script, if a graphic verification code is detected on the current webpage, the interface address of the current webpage is obtained;
[0008] Making a graphic verification code request to the current webpage based on the interface address, and obtaining response data corresponding to the current webpage;
[0009] Extracting verification code parameters corresponding to the graphic verification code from the response data based on a preset extraction method, and saving the verification code parameters as an image file;
[0010] The image file is identified based on a preset identification method to determine a text recognition result in the graphic verification code.
[0011] Optionally, the method further includes: obtaining the server root path and the resource path of the interface of the current webpage; and performing string concatenation based on the server root path and the resource path of the interface to obtain the interface address of the current webpage.
[0012] Optionally, the method further includes: determining a request instruction based on a combination of a preset request code, a preset request method and the interface address in the request library; the request library is referenced when a graphic verification code is detected on the current web page; and making a graphic verification code request to the current web page based on the request instruction to obtain response data corresponding to the current web page.
[0013] Optionally, the method further includes: determining a parameter extraction method corresponding to the format type based on the format type of the response data; performing field extraction in the response data based on the parameter extraction method to obtain verification code parameters corresponding to the graphic verification code, and saving the verification code parameters as an image file.
[0014] Optionally, the method further includes: determining a file generation method corresponding to the data type based on the data type of the verification code parameter; and saving the verification code parameter as an image file based on the file generation method.
[0015] Optionally, the method further includes: initializing an identification object based on a preset identification code in a picture verification code recognition library; the picture verification code recognition library is referenced when a graphic verification code is detected on the current web page; performing content recognition on the picture file as a target recognition object to determine a text recognition result in the graphic verification code.
[0016] In a second aspect, an embodiment of the present invention further provides a verification code recognition device, the device comprising:
[0017] An interface address acquisition module is used to acquire the interface address of the current web page if a graphic verification code is detected on the current web page when executing the web page automated test script;
[0018] a response data determination module, configured to make a graphic verification code request to the current webpage based on the interface address, and obtain response data corresponding to the current webpage;
[0019] An image file determination module is configured to extract verification code parameters corresponding to the graphic verification code from the response data based on a preset extraction method, and save the verification code parameters as an image file;
[0020] The text recognition result determination module is used to identify the image file based on a preset recognition method and determine the text recognition result in the graphic verification code.
[0021] In a third aspect, an embodiment of the present invention further provides an electronic device, comprising:
[0022] one or more processors;
[0023] a memory for storing one or more programs;
[0024] When the one or more programs are executed by the one or more processors, the one or more processors implement the verification code recognition method provided by any embodiment of the present invention.
[0025] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the verification code recognition method provided by any embodiment of the present invention.
[0026] In a fifth aspect, an embodiment of the present invention provides a computer program product, including a computer program, which, when executed by a processor, implements the verification code recognition method provided by any embodiment of the present invention.
[0027] The technical solution of the embodiment of the present invention is as follows: when executing a web page automation test script, if a graphic verification code is detected on the current web page, the interface address of the current web page is obtained; based on the interface address, a graphic verification code request is made to the current web page to obtain response data corresponding to the current web page, thereby obtaining response data containing graphic verification code information; based on a preset extraction method, verification code parameters corresponding to the graphic verification code are extracted from the response data, and the verification code parameters are saved as an image file; based on a preset recognition method, the image file is recognized to determine the text recognition result in the graphic verification code, so that the text recognition result of the verification code in the automated test process can be accurately and conveniently recognized, thereby improving the test efficiency and reducing the test time for the tester.
[0028] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present invention, nor is it intended to limit the scope of the present invention. Other features of the present invention will become readily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0030] Figure 1 This is a flow chart of a verification code recognition method provided in Example 1 of the present invention;
[0031] Figure 2 This is a flow chart of a verification code recognition method provided by the second embodiment of the present invention;
[0032] Figure 3This is a schematic diagram of the structure of a verification code recognition device provided by the third embodiment of the present invention;
[0033] Figure 4 The figure is a schematic diagram of the structure of an electronic device for implementing the verification code recognition method according to an embodiment of the present invention. DETAILED DESCRIPTION
[0034] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions 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 embodiments described 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 making creative efforts should fall within the scope of protection of the present invention.
[0035] It should be noted that the terms "first", "second", etc. in the description 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 numbers 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 clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0036] Example 1
[0037] Figure 1 A flowchart of a verification code recognition method is provided for the first embodiment of the present invention. This embodiment is applicable to the case of automatically recognizing graphic verification codes in web pages. The method can be executed by a verification code recognition device, which can be implemented in the form of hardware and / or software and can be configured in an electronic device. Figure 1 As shown, the method includes:
[0038] S110 . When executing the webpage automated test script, if it is detected that a graphic verification code exists on the current webpage, the interface address of the current webpage is obtained.
[0039] Among them, the web page automation test script may refer to a script that automatically tests the functions of the developed web page. For example, the web page automation test script may be, but is not limited to, a script that tests whether the enterprise internal management system in the web page can log in, query and edit normally. The current web page may refer to the web page that is currently executing the script operation. The current web page needs to perform simulated human operations during the execution of the test script. For example, the current web page may be, but is not limited to, the enterprise internal management system login web page, query web page or editing web page. A graphic verification code is a type of verification code. A graphic verification code may refer to a picture containing random characters (such as numbers, letters or symbols) displayed. A graphic verification code can be used to require the user to enter the correct content to verify the identity. The function of the graphic verification code is to distinguish between real users and automated programs. The interface address may refer to the interface information for the local device to access the graphic verification code in the current web page.
[0040] Specifically, when executing a webpage automated testing script, if the parameters required to be filled in from the current webpage contain a graphic verification code, indicating that the current webpage has a graphic verification code, the interface address for requesting the graphic verification code can be located by analyzing the webpage source code or using a packet capture tool (such as a browser developer tool). The presence of a graphic verification code on the current webpage can also be determined by the length of time the user stays on the current webpage.
[0041] In this embodiment, the interface address may be a Universal Resource Locator (URL) of the graphic verification code.
[0042] Based on the above technical solution, "obtaining the interface address of the current web page" may include: obtaining the server root path and the resource path of the interface of the current web page; performing string splicing based on the server root path and the resource path of the interface to obtain the interface address of the current web page.
[0043] The server root path can refer to the base address of the server. For example, the server root path can be, but is not limited to, "https: / / api.example.com." The resource path of an interface can indicate that the interface's functionality is related to "verification code verification" (such as sending or verifying a graphic verification code). For example, the resource path of an interface can be, but is not limited to, " / v1 / account / checkCode."
[0044] In this embodiment, the interface address is a complete API interface address. By string concatenation, the server root path (https: / / api.example.com) and the interface resource path ( / v1 / account / checkCode) are combined into a complete API interface address (https: / / api.example.com / v1 / account / checkCode).
[0045] S120: Requesting a graphic verification code from the current webpage based on the interface address, and obtaining response data corresponding to the current webpage.
[0046] The response data may refer to the response result of the current webpage to the graphic verification code request. In this embodiment, the graphic verification code request is an HTTP request sent to a specified interface address.
[0047] Specifically, based on the pre-generated HTTP request, a request for a graphic verification code is made to the current webpage through the interface address, thereby obtaining response data fed back by the current webpage in response to the request.
[0048] S130: Extract verification code parameters corresponding to the graphic verification code from the response data based on a preset extraction method, and save the verification code parameters as an image file.
[0049] The preset extraction method may be, but is not limited to, a regular expression or an abstract syntax tree technique. The verification code parameter may refer to a parameter used to write a graphic verification code. The image file may refer to a graphic verification code saved in a file format.
[0050] Based on the above technical solution, "extracting the verification code parameters corresponding to the graphic verification code from the response data based on a preset extraction method, and saving the verification code parameters as a picture file" may include: determining the parameter extraction method corresponding to the format type based on the format type of the response data; performing field extraction in the response data based on the parameter extraction method to obtain the verification code parameters corresponding to the graphic verification code, and saving the verification code parameters as a picture file.
[0051] The format type may refer to the data format of the response data. For example, the format type may be, but is not limited to, HTML format or XML format. The parameter extraction method may refer to the parameter extraction method for response data in different formats.
[0052] Specifically, taking the JSON format of the response data as an example, field extraction is performed from the response data using a step-by-step extraction method to obtain verification code parameters corresponding to the graphic verification code, and the verification code parameters are saved as an image file.
[0053] Based on the above technical solution, "saving the verification code parameters as an image file" may include: determining a file generation method corresponding to the data type based on the data type of the verification code parameters; and saving the verification code parameters as an image file based on the file generation method.
[0054] The data type may be, but is not limited to, binary data or a Base64 encoded string.
[0055] Specifically, if the data type of the verification code parameter is binary data, the verification code parameter can be directly saved as an image file. If the data type of the verification code parameter is a Base64 encoded string, the verification code parameter needs to be converted into binary data first, and the converted binary data is saved as an image file.
[0056] S140: Identify the image file based on a preset identification method to determine a text recognition result in the graphic verification code.
[0057] The preset recognition method may be an image file recognition method using optical character recognition (OCR) technology. The text recognition result may refer to all characters (such as numbers, letters or symbols) displayed in the graphic verification code.
[0058] Specifically, the image file is recognized using an OCR technology to determine the text recognition result in the graphic verification code.
[0059] The technical solution of the embodiment of the present invention is as follows: when executing a web page automation test script, if a graphic verification code is detected on the current web page, the interface address of the current web page is obtained; based on the interface address, a graphic verification code request is made to the current web page to obtain response data corresponding to the current web page; based on a preset extraction method, verification code parameters corresponding to the graphic verification code are extracted from the response data, and the verification code parameters are saved as an image file; based on a preset recognition method, the image file is recognized to determine the text recognition result in the graphic verification code, so as to accurately and conveniently recognize the text recognition result of the verification code during the automated test process, thereby improving the test efficiency and reducing the test time for the tester.
[0060] Building on the above technical solution, this method also includes: after determining the text recognition result of the graphic verification code, the text recognition result and other filled-in content (such as the account number) can be sent to the current webpage and automatically filled into the corresponding input box to complete the entry of all data on the current webpage. After the entry is completed, the test can continue, thus avoiding manual judgment and filling of the graphic verification code, achieving fully automated testing and further improving testing efficiency.
[0061] Example 2
[0062] Figure 2 This is a flowchart of a verification code recognition method provided by the second embodiment of the present invention. Based on the above embodiment, this embodiment describes in detail the process of determining the response data and text recognition results using the referenced function library. The explanations of the terms that are the same or corresponding to the above embodiments are not repeated here. Figure 2 As shown, the method includes:
[0063] S210: When executing the webpage automated test script, if it is detected that a graphic verification code exists on the current webpage, the interface address of the current webpage is obtained.
[0064] In this embodiment, when executing the web page automation test script, if it is detected that there is a graphic verification code on the current web page, the Base library (base64), the request library (requests) and the picture verification code recognition library (ddddocr) are referenced. The Base library, the request library and the picture verification code recognition library are all function libraries written in Python. The code in the Base library can provide the function of converting binary data into and out of Base64 encoded strings. The request library can be used to simplify the sending and response processing of HTTP requests and is one of the core tools for network programming, crawler development and API interaction. The picture verification code recognition library can be used for verification code recognition (such as numbers, letters, sliders, clicks, etc.). For example, the picture verification code recognition library can achieve high-precision recognition based on a deep learning model, and can also implement traditional character verification codes to recognize letter and number combinations (such as xnen or AB3D) in pictures. All the operations of this embodiment can be written into corresponding codes and embedded in the web page automation test script in code form to wait for triggering.
[0065] For example, you can use "import base64," "import requests," and "import ddddocr" to reference the Base library (base64), the Requests library (requests), and the Image Captcha recognition library (ddddocr). Using "url_account_checkCode = config.url + " / v1 / account / checkCode"" you can get the interface address of the current web page and assign the interface address to the variable "url_account_checkCode." "config.url" is the server root path, and " / v1 / account / checkCode" is the resource path of the interface.
[0066] S220: Determine a request instruction based on a combination of a preset request code, a preset request method, and an interface address in a request library; the request library is referenced when a graphic verification code is detected on the current web page.
[0067] The preset request code can be used to combine a preset request method and an interface address to generate a request instruction. The preset request method can be a method for requesting the current webpage. For example, the preset request method can be, but is not limited to, GET or POST. The request instruction can be an HTTP request for a graphic verification code.
[0068] In this embodiment, the predefined graphic verification code request method (GET) can be used to assign the "method_account_checkCode" defined in the config configuration module to the variable "method_account_checkCode" through "method_account_checkCode=config.method_get".
[0069] S230: Requesting a graphic verification code from the current webpage based on the request instruction, and obtaining response data corresponding to the current webpage.
[0070] In this embodiment, "res_account_checkCode = requests.request(url = url_account_checkCode, method = method_account_checkCode)" is used to send an HTTP request to the specified interface address "url_account_checkCode" through the Python requests library, and the request method is set to "method_account_checkCode" (such as GET). The returned response data will be stored or assigned to the variable "res_account_checkCode" and can be used for subsequent identification processing.
[0071] For example, the timeout period may also be specified through “timeout=config.timeout_period”, that is, “res_account_checkCode=requests.request(url=url_account_checkCode, method=method_account_checkCode, timeout=config.timeout_period)”.
[0072] S240: Extract verification code parameters corresponding to the graphic verification code from the response data based on a preset extraction method, and save the verification code parameters as an image file.
[0073] In this embodiment, the format type of the response data is JSON and the data type is base 64. The base 64 formatted graphic verification code parameters are extracted through "base64_image_code=res_account_checkCode.json()['data']['image']" and assigned to "base64_image_code".
[0074] Among them, this embodiment can extract the Base64-encoded graphic verification code string from the JSON response data of the interface and assign it to the variable "base64_image_code". "res_account_checkCode" represents the response data returned after requesting the verification code interface through the requests library. ".json()" parses the response data into JSON format (dictionary or list), and usually requires the "Content-Type" returned by the interface to be "application / json". "['data']['image']" extracts fields step by step from the JSON format response data. "data" represents the business data object returned by the interface. "image" represents the field name. The extracted verification code parameter is a Base64 string that stores the verification code image. The "data:image / png;base64" prefix may be omitted). Finally, the Base64 string is stored in "base64_image_code" for subsequent transcoding or direct use.
[0075] In this embodiment, the string in Base64 format is decoded into binary data through "image_code=base64.b64decode(base64_image_code)" for further processing (such as saving as an image file, OCR recognition, etc.).
[0076] In this embodiment, the binary data is saved as a picture file in PNG format through "with open('image_code.png','wb')as f:" and "f.write(image_code)".
[0077] This command creates and opens files: It opens an image file named "image_code.png" in binary write mode ('wb'). It writes data: It writes the variable "image_code" (which must be binary data) to a file, generating a viewable PNG image. It also uses the "with" statement to automatically close files after operations are completed, preventing resource leaks.
[0078] S250: Initialize a recognition object based on a preset recognition code in a picture verification code recognition library; the picture verification code recognition library is referenced when a graphic verification code is detected on the current web page.
[0079] Initializing the recognition object may refer to creating a blank recognition object to import an image file containing a graphic verification code as a new recognition object.
[0080] In this embodiment, an OCR recognition object is initialized using the ddddocr library through "ocr=ddddocr.DdddOcr()" for subsequent verification code recognition tasks (such as character, slider, and click verification code).
[0081] Here, "ddddocr.DdddOcr()" calls the DdddOcr class in the ddddocr library to create an OCR instance. "ocr" is the variable name used to store the instantiated object, which is then used to call recognition methods (such as ".classification()").
[0082] S260: Perform content recognition on the image file as a target recognition object to determine a text recognition result in the graphic verification code.
[0083] The target recognition object may refer to an image file imported into the created OCR object.
[0084] In this embodiment, the verification code image file is opened through "with open('image_code.png','rb')as f:" and "image_bytes=f.read()".
[0085] When opening a file, "open('image_code.png','rb')" opens the image file named "image_code.png" in binary read-only mode. The "r" in "'rb'" stands for read, and the "b" stands for binary, which is suitable for non-text files (such as images and videos). When reading the file contents, "f.read()" reads all the binary data in the file and stores it in the variable "image_bytes." "image_bytes" represents the bytes type and can be used directly for image processing or transmission. When automatically closing a file, the "with" statement ensures that the file is automatically closed after the file operation is completed, avoiding resource leaks.
[0086] In this embodiment, the OCR engine is called through "image_code_text=ocr.classification(image_bytes)" to recognize the binary image data, extract the text content in the verification code, and store it in the variable "image_code_text".
[0087] Here, "ocr" represents the OCR object initialized using "ddddocr.DdddOcr()." "classification()" represents the core method of the OCR engine, used to perform character recognition on the input image. "image_bytes" represents the binary data of the image (which can be obtained using open('image.png','rb').read()). "image_code_text" represents the text recognition result (string type). For example, the text recognition result can be, but is not limited to, "xnen" or "3Ad8."
[0088] In this embodiment, the value of the variable "image_code_text" (i.e., the text recognition result) is output to the console through "print(image_code_text)" so as to be used to display the text recognition result of the verification code or to feed it back to the current web page to realize automatic filling of the verification code.
[0089] "image_code_text" represents the variable storing the verification code text (for example, the string "xnen" identified by ddddocr). "print()" is a built-in Python function that prints the contents within the brackets to the standard output (such as the terminal or command line window).
[0090] The technical solution of the embodiment of the present invention determines the request instruction by combining the preset request code, preset request method and interface address in the request library; the request library is referenced when a graphic verification code is detected on the current web page; a graphic verification code request is made to the current web page based on the request instruction to obtain the response data corresponding to the current web page. The recognition object is initialized based on the preset recognition code in the image verification code recognition library; the image verification code recognition library is referenced when a graphic verification code is detected on the current web page; the image file is used as the target recognition object for content recognition to determine the text recognition result in the graphic verification code. The function code embedded in the web page automation test script can be used to reference various function libraries, and the embedded code can be used in conjunction with the function library to realize the rapid acquisition and accurate recognition of the parameters of the graphic verification code in the current web page, further saving the time of graphic verification code recognition during the test process, improving the test efficiency and reducing the test time for the tester.
[0091] The following is an embodiment of a verification code recognition device provided by an embodiment of the present invention. The device and the verification code recognition methods of the above embodiments belong to the same inventive concept. For details not fully described in the embodiment of the verification code recognition device, please refer to the embodiment of the above verification code recognition method.
[0092] Example 3
[0093] Figure 3 This is a schematic diagram of the structure of a verification code recognition device provided by the third embodiment of the present invention. Figure 3 As shown, the device includes: an interface address acquisition module 310, a response data determination module 320, an image file determination module 330 and a text recognition result determination module 340.
[0094] Among them, the interface address acquisition module 310 is used to obtain the interface address of the current web page if a graphic verification code is detected on the current web page when executing the web page automation test script; the response data determination module 320 is used to make a graphic verification code request to the current web page based on the interface address, and obtain the response data corresponding to the current web page; the image file determination module 330 is used to extract the verification code parameters corresponding to the graphic verification code from the response data based on a preset extraction method, and save the verification code parameters as an image file; the text recognition result determination module 340 is used to identify the image file based on a preset recognition method, and determine the text recognition result in the graphic verification code.
[0095] The technical solution of the embodiment of the present invention is as follows: when executing a web page automation test script, if a graphic verification code is detected on the current web page, the interface address of the current web page is obtained; based on the interface address, a graphic verification code request is made to the current web page to obtain response data corresponding to the current web page, thereby obtaining response data containing graphic verification code information; based on a preset extraction method, verification code parameters corresponding to the graphic verification code are extracted from the response data, and the verification code parameters are saved as an image file; based on a preset recognition method, the image file is recognized to determine the text recognition result in the graphic verification code, thereby accurately and conveniently recognizing the text recognition result of the verification code during the automated test process, thereby improving the test efficiency and reducing the test time for the tester.
[0096] Based on the above technical solution, the interface address acquisition module 310 is specifically used to: obtain the server root path and interface resource path of the current webpage; and perform string concatenation based on the server root path and interface resource path to obtain the interface address of the current webpage.
[0097] Based on the above technical solution, the response data determination module 320 is specifically used to: determine the request instruction based on the preset request code, preset request method and interface address in the request library; the request library is referenced when a graphic verification code is detected on the current web page; based on the request instruction, a graphic verification code request is made to the current web page to obtain the response data corresponding to the current web page.
[0098] Based on the above technical solution, the picture file determination module 330 may include:
[0099] A parameter extraction method determination submodule is used to determine the parameter extraction method corresponding to the format type based on the format type of the response data;
[0100] The picture file saving submodule is used to extract fields in the response data based on the parameter extraction method, obtain the verification code parameters corresponding to the graphic verification code, and save the verification code parameters as a picture file.
[0101] Based on the above technical solution, the picture file saving submodule is specifically used to: determine the file generation method corresponding to the data type based on the data type of the verification code parameter; and save the verification code parameter as a picture file based on the file generation method.
[0102] Based on the above technical solution, the text recognition result determination module 340 is specifically used to: initialize the recognition object based on the preset recognition code in the image verification code recognition library; the image verification code recognition library is referenced when a graphic verification code is detected on the current web page; use the image file as the target recognition object for content recognition, and determine the text recognition result in the graphic verification code.
[0103] The verification code recognition device provided in the embodiment of the present invention can execute the verification code recognition method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of executing the verification code recognition method.
[0104] It is worth noting that in the above-mentioned embodiment of verification code recognition, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.
[0105] Example 4
[0106] Figure 4 A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or claimed herein.
[0107] like Figure 4As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., which is communicatively connected to the at least one processor 11. The memory stores a computer program that can be executed by the at least one processor. The processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 into the random access memory (RAM) 13. Various programs and data required for the operation of the electronic device 10 can also be stored in the RAM 13. The processor 11, ROM 12, and RAM 13 are connected to each other via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0108] Multiple components in the electronic device 10 are connected to the I / O interface 15, including an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a magnetic disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.
[0109] The processor 11 can be any general-purpose and / or specialized processing component with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various specialized artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as the verification code recognition method.
[0110] In some embodiments, the verification code recognition method can be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as the storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the verification code recognition method described above can be performed. Alternatively, in other embodiments, the processor 11 can be configured to perform the verification code recognition method in any other appropriate manner (for example, by means of firmware).
[0111] Various embodiments of the systems and techniques described herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), system-on-chip systems (SOCs), programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include being implemented in one or more computer programs that are executable and / or interpreted on a programmable system that includes at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0112] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when the computer program is executed by the processor, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The computer program may be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0113] In the context of the present invention, computer-readable storage media can be tangible media that can contain or store a computer program for use with an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. Computer-readable storage media can include but are not limited to electronic, magnetic, optical, electromagnetic, infrared or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, computer-readable storage media can be machine-readable signal media. More specific examples of machine-readable storage media can include electrical connections based on one or more lines, portable computer disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), optical fibers, portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0114] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0115] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0116] A computing system may include clients and servers. The clients and servers are typically remote from each other and typically interact via a communication network. This client-server relationship arises through computer programs running on the respective computers, creating a client-server relationship. The server may be a cloud server, also known as a cloud computing server or cloud host. This server is a hosting product within the cloud computing service ecosystem that addresses the management difficulties and limited scalability of traditional physical hosting and VPS services.
[0117] An embodiment of the present invention further provides a computer program product, including a computer program, which, when executed by a processor, implements the verification code recognition method provided in any embodiment of the present application.
[0118] In the process of implementation, the computer program product can be written in one or more programming languages or a combination thereof to write a computer program code for performing the operation of the present invention, and the programming language includes an object-oriented programming language, such as Java, Smalltalk, C++, and also includes a conventional procedural programming language, such as "C" language or similar programming language. The program code can be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (for example, using an Internet service provider to connect through the Internet). The program product belongs to the same inventive concept as the verification code recognition method disclosed in each embodiment of the application, and therefore will not be repeated here.
[0119] It should be understood that the various forms of the processes shown above can be used to reorder, add, or delete steps. For example, the steps described in the present invention can be performed in parallel, sequentially, or in a different order, as long as the desired results of the technical solution of the present invention can be achieved. This is not limited herein.
[0120] The above specific embodiments do not limit the scope of protection of the present invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions may be made based on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention are intended to be included within the scope of protection of the present invention.
Claims
1. A verification code recognition method, characterized in that: include: When executing the webpage automated test script, if a graphic verification code is detected on the current webpage, the interface address of the current webpage is obtained; Making a graphic verification code request to the current webpage based on the interface address, and obtaining response data corresponding to the current webpage; Extracting verification code parameters corresponding to the graphic verification code from the response data based on a preset extraction method, and saving the verification code parameters as an image file; The image file is identified based on a preset identification method to determine a text recognition result in the graphic verification code.
2. The method according to claim 1, characterized in that The obtaining of the interface address of the current webpage includes: Obtain the server root path and interface resource path of the current web page; String concatenation is performed based on the server root path and the resource path of the interface to obtain the interface address of the current webpage.
3. The method according to claim 1, characterized in that The step of requesting a graphic verification code from the current webpage based on the interface address and obtaining response data corresponding to the current webpage includes: Determining a request instruction based on a combination of a preset request code, a preset request method, and the interface address in a request library; the request library is referenced when a graphic verification code is detected on the current web page; A graphic verification code request is made to the current webpage based on the request instruction to obtain response data corresponding to the current webpage.
4. The method according to claim 1, wherein The step of extracting the verification code parameters corresponding to the graphic verification code from the response data based on a preset extraction method, and saving the verification code parameters as an image file, includes: Based on the format type of the response data, determining a parameter extraction method corresponding to the format type; Field extraction is performed in the response data based on the parameter extraction method to obtain verification code parameters corresponding to the graphic verification code, and the verification code parameters are saved as an image file.
5. The method according to claim 4, characterized in that Saving the verification code parameters as a picture file includes: Based on the data type of the verification code parameter, determining a file generation method corresponding to the data type; The verification code parameters are saved as a picture file based on the file generation method.
6. The method according to claim 1, characterized in that The identifying the image file based on a preset identification method to determine the text recognition result in the graphic verification code includes: Initializing the recognition object based on a preset recognition code in a picture verification code recognition library; the picture verification code recognition library is referenced when a graphic verification code is detected on the current web page; The image file is used as a target identification object to perform content identification and determine the text recognition result in the graphic verification code.
7. A verification code recognition device, characterized in that: The device comprises: An interface address acquisition module is used to acquire the interface address of the current web page if a graphic verification code is detected on the current web page when executing the web page automated test script; a response data determination module, configured to make a graphic verification code request to the current webpage based on the interface address, and obtain response data corresponding to the current webpage; An image file determination module is configured to extract verification code parameters corresponding to the graphic verification code from the response data based on a preset extraction method, and save the verification code parameters as an image file; The text recognition result determination module is used to identify the image file based on a preset recognition method and determine the text recognition result in the graphic verification code.
8. An electronic device, characterized in that: The electronic device comprises: 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 implement the verification code recognition method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the verification code recognition method according to any one of claims 1 to 6 is implemented.
10. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the computer program implements the verification code recognition method according to any one of claims 1 to 6.