Data acquisition method and device, medium and equipment

By matching and optimizing crawler scripts, the adaptability problem of crawler scripts when the web page structure changes is solved, efficient and accurate data capture is achieved, and maintenance costs are reduced.

CN118606535APending Publication Date: 2024-09-06SHANGHAI INGOT NETWORK TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202410776302.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-14
Publication Date
2024-09-06

AI Technical Summary

Technical Problem

In the existing technology, crawler scripts are difficult to adapt when the web page structure changes, resulting in incomplete or failed data capture, and manual code debugging is required, which increases maintenance costs and time-consuming.

Method used

By determining the page and data type to be crawled, matching the corresponding crawler script for data crawling, and using the optimization model to adjust the script to adapt to page structure changes, avoiding manual debugging and improving the accuracy and efficiency of data crawling.

Benefits of technology

It reduces the maintenance cost of crawler scripts, improves the accuracy and adaptability of data capture, and avoids the need for manual debugging after data capture failure.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118606535A
    Figure CN118606535A
Patent Text Reader

Abstract

The invention discloses a data acquisition method and device, a medium and equipment, and the method comprises the steps: determining a to-be-captured page and a to-be-captured data type in response to a data capturing request of a user; and determining a crawler script matched with the type of the to-be-captured data from the stored crawler scripts, performing data capture on the to-be-captured page through the matched crawler script, and storing a capture result which at least comprises page data and a page structure. And judging whether the page data is abnormal or not according to a preset rule corresponding to the to-be-captured data type and the page data. If yes, the matched crawler script and the page structure are input into the trained optimization model, and the optimized crawler script is obtained. And according to the optimized crawler script, performing data capture on the to-be-captured page again. And if not, executing subsequent business according to the page data. The problem that the crawler codes need to be manually debugged is avoided, the labor cost is reduced, and the maintenance cost of the crawler scripts is also reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a data acquisition method, device, medium and equipment. Background Art

[0002] At present, with the rapid development of cutting-edge technologies such as big data, cloud computing and artificial intelligence, the amount of data on Internet platforms is growing exponentially. In order to gain in-depth insights and analyze these massive amounts of data to support accurate strategic decision-making, efficient collection of Internet data has become crucial.

[0003] In current technology, specialized crawler scripts are usually customized to crawl specific content on the web pages of Internet platforms, so as to monitor specific content and make strategic decisions in a timely manner. However, when the structure of web pages changes frequently, the customized crawler scripts are often stretched to the limit and cannot complete the task of data crawling well, which easily leads to incomplete or failed data crawling. Existing solutions rely on manual debugging of crawler codes, which is not only time-consuming and labor-intensive, but also significantly increases maintenance costs.

[0004] To this end, this specification provides a data acquisition method, device, medium and equipment. Summary of the invention

[0005] This specification provides a data acquisition method, device, medium and equipment to partially solve the above-mentioned problems existing in the prior art.

[0006] This manual adopts the following technical solutions:

[0007] This specification provides a data acquisition method, including:

[0008] In response to a user's data crawling request, determine the page to be crawled and the type of data to be crawled;

[0009] Determine a crawler script that matches the data type to be crawled from the stored crawler scripts, crawl data of the page to be crawled by using the matching crawler script, and store the crawling result, which includes at least page data and page structure;

[0010] According to the preset rules corresponding to the data type to be captured and the page data, determining whether the page data is abnormal;

[0011] If yes, the matching crawler script and the page structure are input into the trained optimization model to obtain an optimized crawler script; and data of the page to be crawled is crawled again according to the optimized crawler script;

[0012] If not, subsequent services are performed according to the page data.

[0013] Optionally, the trained optimization model includes an analysis sub-model and an update sub-model;

[0014] Inputting the matched crawler script and the page structure into the trained optimization model to obtain an optimized crawler script, specifically including:

[0015] Inputting the matched crawler script and the page structure into the analysis sub-model to obtain abnormal factors output by the analysis sub-model;

[0016] The abnormal factors and the matching crawler script are input into the update sub-model to obtain an optimized crawler script output by the update sub-model.

[0017] Optionally, the optimization model is trained using the following method, wherein:

[0018] For each data type to be captured, determine the historical versions of the crawler script that match the data type, the page structures captured by each historical version, and the optimization model to be trained;

[0019] For each historical version, the historical version and the page structure captured by the historical version are used as training samples, and the iterative version of the historical version is determined, as well as the abnormal factors captured by the historical version;

[0020] Inputting the training sample into the analysis sub-model in the optimization model to be trained, and obtaining the abnormal factors output by the analysis sub-model in the optimization model to be trained;

[0021] According to the abnormal factors in the page structure captured by the historical version and the differences between the abnormal factors outputted, training the analysis sub-model in the optimization model to be trained;

[0022] Input the output abnormal factors and the historical version into the update sub-model in the optimization model to be trained, and output an updated version of the historical version;

[0023] According to the difference between the updated version and the iterative version of the historical version, the updated sub-model in the optimization model to be trained is trained.

[0024] Optionally, the method further includes:

[0025] Determine the historical crawling results of the page to be crawled from the historical crawling results of the page to be crawled;

[0026] Determine the target time for data crawling on the page to be crawled according to the crawling time of the normal historical crawling results of the page data;

[0027] According to the target time, data is crawled on the to-be-crawled page through the matching crawler script.

[0028] Optionally, the crawling result also includes a page status code;

[0029] Before determining whether the page data is abnormal based on the preset rules corresponding to the data type to be captured and the page data, the method further includes:

[0030] Determine whether the page status code in the crawling result matches the preset abnormal status code;

[0031] If so, an abnormality warning is returned to the user, where the abnormality warning is used to prompt that the data of the page to be crawled is abnormal.

[0032] Optionally, returning an abnormality warning to the user, specifically including:

[0033] After a preset time, according to the matched crawler script, continue to crawl data on the to-be-crawled page, and determine whether the page status code in the crawling result matches the preset abnormal status code;

[0034] If yes, an alarm phone number is returned to the user, where the alarm phone number is used to prompt the user that data capture has failed;

[0035] If not, a warning email is returned to the user, where the warning email is used to prompt the user that the history crawling is abnormal.

[0036] Optionally, before storing the crawling result, the method further includes:

[0037] Determine the time taken by the matching crawler script to crawl the page to be crawled;

[0038] According to the crawling time consumption, determining whether the crawling time consumption is greater than a preset time consumption;

[0039] If so, after waiting for a preset time interval, continue to crawl data of the to-be-crawled page through the matching crawler script.

[0040] This specification provides a data acquisition device, including:

[0041] A determination module, used to determine the page to be crawled and the type of data to be crawled in response to the user's data crawling request;

[0042] A crawling module, used to determine a crawler script matching the data type to be crawled from the stored crawler scripts, crawl data of the page to be crawled through the matching crawler script, and store the crawling results, which at least include page data and page structure;

[0043] A judgment module is used to judge whether the page data is abnormal according to the preset rules corresponding to the data type to be crawled and the page data; if so, the matching crawler script and the page structure are input into the trained optimization model to obtain an optimized crawler script; according to the optimized crawler script, the data of the page to be crawled is crawled again; if not, subsequent business is executed according to the page data.

[0044] This specification provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the above-mentioned data acquisition method is implemented.

[0045] This specification provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements a data acquisition method when executing the program.

[0046] At least one of the above technical solutions adopted in this specification can achieve the following beneficial effects:

[0047] The data acquisition method provided in this specification first responds to the user's data crawling request to determine the page to be crawled and the type of data to be crawled. From the stored crawler scripts, determine the crawler script that matches the data type to be crawled, crawl the data of the page to be crawled through the matching crawler script, and store the crawling results, which at least include page data and page structure. According to the preset rules corresponding to the data type to be crawled, and the page data, determine whether the page data is abnormal. If so, input the matching crawler script and the page structure into the trained optimization model to obtain the optimized crawler script. According to the optimized crawler script, crawl the data of the page to be crawled again. If not, execute subsequent business according to the page data.

[0048] By determining the matching crawler script based on the type of data to be crawled, the content to be crawled can be crawled. The crawler script to be crawled is used to crawl data on the page to be crawled. When an abnormal situation occurs during the data crawling process, the matching crawler script and the page structure of the page to be crawled are input into the optimization model to obtain the optimized crawler script. This avoids the problem of manually debugging the crawler code after data crawling fails, which not only reduces labor costs, but also reduces the cost of crawler script maintenance, making the crawler script's adaptation process after the page structure changes faster and more efficient, and improving the accuracy of data crawling. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] The drawings described herein are used to provide a further understanding of this specification and constitute a part of this specification. The illustrative embodiments and descriptions of this specification are used to explain this specification and do not constitute an improper limitation on this specification. In the drawings:

[0050] Figure 1 A flowchart of a data acquisition method provided in an embodiment of this specification;

[0051] Figure 2 A schematic diagram of an optimized crawler script provided in this specification;

[0052] Figure 3 A schematic diagram of an optimization model for optimizing crawler scripts provided in this specification;

[0053] Figure 4 A schematic diagram of a data acquisition device provided in this specification;

[0054] Figure 5 A method corresponding to the Figure 1 Schematic diagram of the structure of an electronic device. DETAILED DESCRIPTION

[0055] In order to make the purpose, technical solutions and advantages of this specification more clear, the technical solutions of this specification will be clearly and completely described below in combination with the specific embodiments of this specification and the corresponding drawings. Obviously, the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0056] The technical solutions provided by the embodiments of this specification are described in detail below in conjunction with the accompanying drawings.

[0057] Figure 1 A flow chart of a data capture method provided in an embodiment of this specification includes the following steps:

[0058] S100: In response to a user's data crawling request, determine the page to be crawled and the type of data to be crawled.

[0059] In the process of data acquisition in this specification, in the embodiments of this specification, the data acquisition process can be executed by a server. Of course, this specification does not limit which device is used to implement the data acquisition process, and data acquisition can also be performed by devices such as personal computers and mobile terminals. For the convenience of description, the following description is based on the server as the execution subject.

[0060] In one or more embodiments of the present specification, the server responds to the user's data capture request, and determines the page to be captured and the data type to be captured according to the data capture request. Wherein, determining the page to be captured can be determining the URL of the page to be captured, which is uploaded to the server together with the data capture request when the user initiates the data capture request. The data type to be captured can be represented as the name of the data that the user wants to capture in the present specification. For example, the market analysis team of a game development company needs to regularly capture data from a game ranking website to understand the ranking and user evaluation of games developed by competitors. Then, the name of the data that the market analysis team wants to capture is the game name, game ranking, and the number of comments. The game name, game ranking, and the number of comments are data of different data types. On the game ranking website, there are both data of the data type that the market analysis team wants to obtain and data of the data type that the market analysis team does not want to obtain. According to the data of the data type that the market analysis team wants to obtain, the data type to be captured is determined, that is, the data type to be captured is the game name, game ranking, and the number of comments.

[0061] S102: Determine a crawler script that matches the data type to be crawled from the stored crawler scripts, crawl data of the page to be crawled using the matching crawler script, and store the crawling results, which at least include page data and page structure.

[0062] In one or more embodiments of the present specification, if the data type that the user wants to crawl is different, then the required crawler script is also different. Therefore, it is necessary to determine a matching crawler script from the stored crawler scripts according to the data type to be crawled. The crawler script that can crawl data of the data type to be crawled is the matching crawler script.

[0063] In one or more embodiments of the present specification, the server determines a crawler script that matches the data type to be crawled from the stored crawler scripts. The crawler script that matches the crawled page is used to crawl data, and the crawling results are stored. The crawling results include at least page data and page structure.

[0064] The page data in the crawling results is the data that the user wants to crawl. The page structure in the crawling results is the code structure of the front-end page layout of the page to be crawled.

[0065] For example, the market analysis team of a game development company needs to regularly crawl data from a game ranking website to understand the rankings and user reviews of games developed by competitors. Then, the data that the market analysis team wants to crawl is the game name, game ranking, and number of comments. The page data is the specific game name, game ranking, and number of comments, such as Game A, ranking 20, and 6,000 comments. The page structure refers to the code structure of the various layouts on the front-end page of the game ranking website. For example, the front-end page of the game ranking website has a Cascading Style Sheets (CSS) class for rendering game rankings, so the CSS class for rendering game rankings is part of the page structure, and the code structure of the front-end page is the complete page structure.

[0066] It is worth noting that if the server determines that there is no crawler script matching the data type to be crawled from the stored crawler scripts, a prompt message is returned to the user to prompt the user to develop a crawler script according to the data type to be crawled. In this specification, the Scrapy crawler framework can be used to develop crawler scripts. This specification does not limit the crawler framework or crawler script generation tool used to develop crawler scripts. The tool for storing crawling results can be recorded in logs or stored in a database, which is not limited by this specification.

[0067] S104: According to the preset rules corresponding to the data type to be captured and the page data, determine whether the page data is abnormal. If so, execute step S106; if not, execute step S108.

[0068] In one or more embodiments of the present specification, the server determines whether the captured page data is abnormal based on the preset rules corresponding to the data type to be captured and the page data captured by the crawler script. If so, step S106 is executed, and if not, step S108 is executed.

[0069] The server determines whether the captured page data is abnormal according to the preset rules corresponding to the data type to be captured. The preset rules can be the rules set by the page to be captured for the data type to be captured.

[0070] For example, taking a game ranking website as an example, the content length of user comments about games posted on the game ranking website is specified to be 1 to 2000 bytes. In order to crawl the specific content of user comments through a crawler script, the crawler user who obtains the specific content of user comments can judge the reputation of the game based on the user comments. Then, when using a crawler script to crawl user comments, normally, the content length of the user comments that should be crawled is 1 to 2000 bytes. If the content length of the page data (i.e., user comments) in the crawled results is outside the range of 1 to 2000 bytes, the crawled page data is abnormal.

[0071] Of course, the preset rule can also be to determine whether the captured page data is empty. If the page data captured by the crawler script is empty, it is empty data, and no content is captured on the page to be captured, it is an exception. Alternatively, the preset rule is to determine whether the data types to be captured correspond to the content on the page to be captured, and whether the captured content is not empty. If the crawler script does not capture the content corresponding to some or all of the data types in the data types to be captured, it is considered an exception.

[0072] For example, take crawling data from a game ranking website as an example, the data types to be crawled are game names and game rankings. Then the matching crawler script crawls the data of the game ranking website. Normally, the data that should be crawled are specific game names and game rankings. However, if the crawler script does not crawl the specific game name and game ranking, or crawls only one of the game name and game ranking, it is considered that the crawled page data is abnormal.

[0073] It is worth noting that, it is also possible to determine whether the number matches the preset value based on the number of specific contents of the data type to be crawled on the page to be crawled. If so, it is determined that the page data crawled by the crawler script is normal. If not, it is determined that the page data crawled by the crawler script is abnormal.

[0074] For example, take crawling data on a game ranking website as an example. The data types to be crawled are game names and game rankings. The game ranking website will list the top 100 games, that is, 100 games and their rankings will appear on the game ranking website. Then, the matching crawler script crawls the data of the game ranking website. Normally, the data that should be crawled are 100 specific game names and game rankings. If only 80 are crawled, it is considered that the crawled page data is abnormal.

[0075] S106: Input the matched crawler script and the page structure into the trained optimization model to obtain an optimized crawler script; and re-crawl data on the page to be crawled according to the optimized crawler script.

[0076] In one or more embodiments of the present specification, the server inputs the matched crawler script and the page structure into the trained optimization model to obtain an optimized crawler script. According to the optimized crawler script, data is re-crawled on the page to be crawled.

[0077] In one or more embodiments of the present specification, the method for training the optimization model may be, for each data type to be captured, determining each historical version of the crawler script that matches the data type, the page structure captured by each historical version, and the optimization model to be trained. For each historical version, the historical version and the page structure captured by the historical version are used as training samples, and the iterative version of the historical version is used as the annotation of the training sample. The training sample is input into the optimization model to be trained to obtain an updated version of the historical version in the training sample. The loss is determined based on the difference between the updated version and the annotation of the training sample, and the optimization model to be trained is trained with the minimum loss as the optimization goal.

[0078] Figure 2 This is a schematic diagram of an optimized crawler script provided in this manual. Figure 2 As shown, the crawler script and the page structure it crawls are input into the optimization model to obtain the optimized crawler script output by the optimization model.

[0079] S108: Execute subsequent services according to the page data.

[0080] In one or more embodiments of the present specification, after the server determines that the page data crawled by the matching crawler script is normal, subsequent services may be executed based on the page data.

[0081] For example, the market analysis team of a game development company needs to regularly crawl data from a game ranking website to understand the rankings and user reviews of games developed by competitors. After obtaining the page data (i.e., the rankings and user reviews of games developed by competitors), the market analysis team can formulate strategies based on the page data, analyze the competitiveness of competitors, and other follow-up businesses.

[0082] based on Figure 1The data acquisition method provided in this specification first responds to the user's data crawling request to determine the page to be crawled and the type of data to be crawled. From the stored crawler scripts, determine the crawler script that matches the data type to be crawled, and crawl the data of the page to be crawled through the matching crawler script, and store the crawling results, which at least include page data and page structure. According to the preset rules corresponding to the data type to be crawled, and the page data, determine whether the page data is abnormal. If so, input the matching crawler script and the page structure into the trained optimization model to obtain the optimized crawler script. According to the optimized crawler script, crawl the data of the page to be crawled again. If not, execute subsequent business according to the page data.

[0083] By determining the matching crawler script based on the type of data to be crawled, the content to be crawled can be crawled. The crawler script to be crawled is used to crawl data on the page to be crawled. When an abnormal situation occurs during the data crawling process, the matching crawler script and the page structure of the page to be crawled are input into the optimization model to obtain the optimized crawler script. This avoids the problem of manually debugging the crawler code after data crawling fails, which not only reduces labor costs, but also reduces the cost of crawler script maintenance, making the crawler script's adaptation process after the page structure changes faster and more efficient, and improving the accuracy of data crawling.

[0084] In addition, in one or more embodiments of the present specification, the trained optimization model may also include an analysis sub-model and an update sub-model.

[0085] Specifically, the server inputs the matching crawler script and page structure into the analysis sub-model in the trained optimization model to obtain the abnormal factors output by the analysis sub-model. The server inputs the abnormal factors and the matching crawler script into the update sub-model in the trained optimization model to obtain the optimized crawler script output by the update sub-model.

[0086] Figure 3 This is a schematic diagram of an optimization model for optimizing crawler scripts provided in this specification. Figure 3 As shown, the crawler script and page structure are input into the analysis sub-model of the optimization model, the analysis sub-model outputs abnormal factors to the update sub-model, and the update sub-model is then updated according to the crawler script to obtain an updated version, that is, the optimized crawler script.

[0087] In one or more embodiments of the present specification, the method for training an optimization model including an analysis submodel and an update submodel may be, for each data type to be captured, determining each historical version of the crawler script that matches the data type, the page structure captured by each historical version, and the optimization model to be trained. For each historical version, the historical version and the page structure captured by the historical version are used as training samples, and the iterative version of the historical version is determined, and the abnormal factors captured by the historical version are determined. Among them, the abnormal factors captured by the historical version may be abnormal factors in the page structure captured by the historical version, or may be abnormal factors obtained by changing the front-end layout of the page to be captured. The training sample is input into the analysis submodel in the optimization model to be trained to obtain the abnormal factors output by the analysis submodel in the optimization model to be trained. According to the difference between the abnormal factors in the page structure captured by the historical version and the abnormal factors output by the analysis submodel, the loss is determined, and the analysis submodel in the optimization model to be trained is trained with the minimum loss as the optimization goal.

[0088] The abnormal factors and the historical version of the sub-model output are analyzed and input into the updated sub-model in the optimization model to be trained, and the updated version of the historical version is output. The loss is determined based on the difference between the updated version and the iterative version of the historical version, and the updated sub-model in the optimization model to be trained is trained with the minimum loss as the optimization goal.

[0089] In one or more embodiments of the present specification, in order to increase the success rate of crawler scripts in crawling data of the crawled pages and reduce the consumption of server computing resources, before crawling data of the crawler scripts, statistics can be collected during the crawling process of the crawled pages to be crawled, and the time period in which the historical crawling results of the normal page data are crawled can be determined. Thus, a time period with more historical crawling results of normal page data is selected as the time selection range for the crawler script to crawl the pages to be crawled. When the crawler script crawls the pages to be crawled, it only needs to randomly select a time from the time selection range to start data crawling. Among them, more in the time period with more historical crawling results means that the number of historical crawling results is more than the preset number.

[0090] Specifically, the server determines the historical crawling results of the page to be crawled from the historical crawling results of the page to be crawled, and then determines the target time for crawling data on the page to be crawled according to the crawling time of the historical crawling results of the page data to be crawled. According to the target time, the server crawls data on the page to be crawled through the matching crawler script.

[0091] For example, taking the data crawling on the game ranking website as an example, the market analysis team of a game development company needs to crawl the data of a game ranking website regularly. Then, based on the historical crawling results of the game ranking website, determine the historical crawling results of normal page data. If there are 60 normal crawling results of crawling page data in the time period of 1:00-5:00, reaching the preset number of times of the market analysis team. Then, it can be considered that the success rate of crawling data in the time period of 1:00-5:00 is higher. When crawling data on the game ranking website through the crawler script, you can choose 1:25 or 3:26 to crawl data.

[0092] In one or more embodiments of the present specification, the crawling result also includes a page status code.

[0093] Before judging whether the page data is abnormal, the server can also judge whether the page status code in the crawl result matches the preset abnormal status code based on the preset rules corresponding to the data type to be crawled and the page data. If so, an abnormality alarm is returned to the user, which is used to prompt the crawling of the page data to be crawled abnormally.

[0094] The page status code and the preset abnormal status code are both Hypertext Transfer Protocol (HTTP) status codes.

[0095] Abnormal status codes include at least: 301 (The Uniform Resource Locator (URL) of the page to be crawled has been permanently changed), 302 (The Uniform Resource Identifier (URI) of the page to be crawled has been temporarily changed. Further changes to the URI may be made in the future.), 303 (Indicates that the resource of the page to be crawled is obtained at another URI through a GET request.), 307 (Indicates that the resource of the page to be crawled is obtained at another URI using the same method used in the previous request. This has the same semantics as 302), 308 (This means that the resource is now permanently located at the Location: HTTP Response header. This has the same semantics as 301.), 400 (The server cannot or will not process the request due to what is believed to be a crawler script error (for example, incorrect request syntax, invalid request message framing, or deceptive request routing).), 401 (You must authenticate yourself to get a response to the request.), 403 (No permission to access the content.), 404 (The resource for the page to be crawled cannot be found.), 405 (The request method is not supported by the page to be crawled.), 407 (Similar to 401 but authentication needs to be done by a proxy.), 410 (This response is sent when the content of the page to be crawled has been permanently deleted and there is no forwarding address.), 411 (The request is rejected because the Content-Length header field is undefined.), 413 (The request entity (the page to be crawled) is larger than the limit defined by the server. The server may close the connection or return a retry after the Retry-After header field.), 414 (The requested URI is longer than the server where the page to be crawled is willing to accept.), 4 15 (The requested media format is not supported), 416 (The range specified by the Range header field in the request cannot be met.), 417 (Indicates that the expectation indicated by the Expect request header field cannot be met.), 418 (Rejected by the server.), 421 (The request was directed to a server that could not generate a response.), 422 (The request format is correct, but it cannot be followed due to semantic errors.), 423 (The resource being accessed (the page to be crawled) is locked.), 429 (Too many requests were sent in a given time), 431 (Unwilling to process the request because its header field is too large. The request can be resubmitted after reducing the size of the request header field.), 451 (Resources that cannot be legally provided, such as web pages censored by the government.), 500 (The server where the page to be crawled is located encountered a situation that it does not know how to handle.), 501 (The server where the page to be crawled is located does not support the request method and therefore cannot process it.), 502 (Get an error response.), 503 (The server where the page to be crawled is located is not ready to process the request. Common reasons are that the server is down due to maintenance or overload.), 504 (This error response is given when the server where the page to be crawled is located acts as a gateway and cannot get a response in time.), 505 (The server where the page to be crawled is located does not support the HTTP version used in the request.), 506 (There is an internal configuration error on the server where the page to be crawled is located), 507 (The server where the page to be crawled is located cannot store the representation required to successfully complete the request.), 508 (The server where the page to be crawled is located detected an infinite loop when processing the request.), 510 (The server where the page to be crawled is located needs to further extend the request to complete the request.), 511 (Authentication is required to obtain network access.).

[0096] In one or more embodiments of the present specification, in order to prevent the occurrence of false alarms when returning abnormal alarms to users, or to warn of situations that do not affect data capture as abnormalities. Therefore, when returning abnormal alarms to users, the server can also continue to crawl data for the crawled page according to the matching crawler script after a preset time, and determine whether the page status code in the crawling result matches the preset abnormal status code. If so, an alarm phone is returned to the user, and the alarm phone is used to prompt the user that the data crawling failed. At this time, after waiting for a period of time, the data crawling continues, and it is still abnormal, which means that the crawling situation has an abnormal emergency. Returning the alarm phone to the user can directly and clearly express the emergency state. If not, an alarm email is returned to the user, and the alarm email is used to prompt the user of historical crawling abnormalities. At this time, after waiting for a period of time, the data crawling continues, and it does not match the abnormal status code, which means that the previous abnormality may be a false alarm. At this time, the abnormal record email of the previous data crawling is returned to the user, prompting the user to check the abnormality.

[0097] In one or more embodiments of the present specification, since there are a large number of abnormal status codes and the meanings represented by the status codes are not necessarily the same, different degrees of abnormal warnings are returned to the user in response to the meanings represented by different abnormal status codes.

[0098] Specifically, according to the different types of matches between the page status code and the abnormal status code, an abnormal warning is returned to the user. When the page status code is of the redirect type, a first-level warning message is returned to the user. When the page status code means a crawler script error, a second-level warning message is returned to the user. When the page status code means a server error, a third-level warning message is returned to the user. Among them, the first-level warning message indicates that the cause of the abnormality is not serious and can be quickly restored after investigation. The status code included in the redirect type is usually a status code starting with the number three, but it does not necessarily start with the number three. The second-level warning message indicates that the cause of the abnormality lies in the crawler script itself, and the crawler script needs to be investigated as soon as possible. The third-level warning message indicates that there is a problem with the server where the page to be crawled is located, and it is necessary to wait for the server maintenance to be completed. There is no need to continue to try to re-crawl the data immediately.

[0099] For example, when the page status code in the crawling result is 301, a first-level warning message is returned to the user to prompt the user that the URL of the page to be crawled has changed. It is necessary to check whether the URL of the page to be crawled in the crawler script is incorrect and determine the correct URL of the page to be crawled. When the page status code in the crawling result is 308, the processing process is similar to that when the page status code is 301. When the page status code in the crawling result is 400, a second-level warning message is returned to the user to prompt the user that the cause of the abnormality lies in the crawler script itself, the crawler script is wrong, and the crawler script needs to be checked as soon as possible. When the page status code in the crawling result is 400, a second-level warning message is returned to the user to prompt the user that the request format is correct, but it cannot be followed due to semantic errors, and the crawler script needs to be checked as soon as possible. When the page status code in the crawling result is 500, a third-level warning message is returned to the user to prompt the user that the server where the page to be crawled is located has encountered a situation that it does not know how to handle, and it is not caused by the crawler script. When the page status code in the crawling result is 503, a third-level warning message is returned to the user, prompting the user that the server where the page to be crawled is located is not ready to process the request. The common reason is that the server is shut down due to maintenance or overload. It is necessary to wait for the server maintenance to be completed, and there is no need to continue to try to crawl data again immediately.

[0100] In one or more embodiments of the present specification, in order to prevent problems such as slow loading when the crawler script accesses the page to be crawled, the crawling frequency and strategy can be adjusted to avoid the peak access period of the page to be crawled.

[0101] Specifically, before storing the crawling results, the server may also determine the crawling time taken by the matching crawler script to crawl the page to be crawled. According to the crawling time, it is determined whether the crawling time is greater than the preset time. If so, after waiting for the preset time interval, the matching crawler script is continued to crawl data for the page to be crawled.

[0102] The above is a data acquisition method provided by one or more embodiments of this specification. Based on the same idea, this specification also provides a corresponding data acquisition device, such as Figure 4 shown.

[0103] Figure 4 A schematic diagram of a data acquisition device provided in this specification specifically includes:

[0104] The determination module 400 is used to determine the page to be crawled and the type of data to be crawled in response to the user's data crawling request;

[0105] The crawling module 402 is used to determine a crawler script that matches the data type to be crawled from the stored crawler scripts, crawl data of the page to be crawled through the matching crawler script, and store the crawling result, which at least includes page data and page structure;

[0106] The judgment module 404 is used to judge whether the page data is abnormal according to the preset rules corresponding to the data type to be crawled and the page data; if so, the matching crawler script and the page structure are input into the trained optimization model to obtain an optimized crawler script; according to the optimized crawler script, the data of the page to be crawled is crawled again; if not, subsequent business is executed according to the page data.

[0107] Optionally, the trained optimization model includes an analysis sub-model and an update sub-model;

[0108] The judgment module 404 is also used to input the matching crawler script and the page structure into the analysis sub-model to obtain abnormal factors output by the analysis sub-model, and input the abnormal factors and the matching crawler script into the update sub-model to obtain the optimized crawler script output by the update sub-model.

[0109] Optionally, the judgment module 404 is also used to determine, for each data type to be captured, the historical versions of the crawler script that matches the data type, the page structures captured by the historical versions, and the optimization model to be trained; for each historical version, use the historical version and the page structure captured by the historical version as training samples, determine the iterative version of the historical version, and determine the abnormal factors captured by the historical version; input the training samples into the analysis sub-model in the optimization model to be trained to obtain the abnormal factors output by the analysis sub-model in the optimization model to be trained; train the analysis sub-model in the optimization model to be trained based on the differences between the abnormal factors in the page structure captured by the historical version and the output abnormal factors; input the output abnormal factors and the historical version into the update sub-model in the optimization model to be trained; output an updated version of the historical version; and train the update sub-model in the optimization model to be trained based on the differences between the updated version and the iterative version of the historical version.

[0110] Optionally, the device further includes a target grabbing module 406;

[0111] The target crawling module 406 is used to determine the historical crawling results of normal page data from the historical crawling results of the page to be crawled, determine the target time for data crawling on the page to be crawled according to the crawling time of the historical crawling results of normal page data, and crawl data on the page to be crawled according to the target time through the matching crawler script.

[0112] Optionally, the crawling result also includes a page status code;

[0113] The judgment module 404 is further used to judge whether the page status code in the crawling result matches the preset abnormal status code. If so, an abnormality alarm is returned to the user, and the abnormality alarm is used to prompt that the crawling of the page data to be crawled is abnormal.

[0114] Optionally, the judgment module 404 is also used to continue to crawl data on the page to be crawled according to the matching crawler script after a preset time, and to determine whether the page status code in the crawling result matches the preset exception status code. If so, an alarm phone call is returned to the user, and the alarm phone is used to prompt the user that the data crawling failed. If not, an alarm email is returned to the user, and the alarm email is used to prompt the user of historical crawling abnormalities.

[0115] The crawling module 402 is also used to determine the time consumed by the matching crawler script to crawl the page to be crawled, and judge whether the crawling time is greater than a preset time based on the crawling time. If so, after waiting for a preset time interval, continue to crawl data of the page to be crawled through the matching crawler script.

[0116] This specification also provides a computer-readable storage medium, which stores a computer program, which can be used to execute the above Figure 1 A data acquisition method is provided.

[0117] This manual also provides Figure 5 The schematic structure diagram of the electronic device shown in FIG. Figure 5 As shown, at the hardware level, the electronic device includes a processor, an internal bus, a network interface, a memory, and a non-volatile memory, and may also include other hardware required for the business. The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it to achieve the above Figure 1 The data acquisition method.

[0118] Of course, in addition to software implementation, this specification does not exclude other implementation methods, such as logic devices or a combination of software and hardware, etc., that is to say, the executor of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.

[0119] In the 1990s, improvements to a technology could be clearly distinguished as hardware improvements (for example, improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the method flow). However, with the development of technology, many improvements to the method flow today can be regarded as direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that an improvement in a method flow cannot be implemented using a hardware entity module. For example, a programmable logic device (PLD) (such as a field programmable gate array (FPGA)) is such an integrated circuit whose logical function is determined by the user's programming of the device. Designers can "integrate" a digital system on a PLD by programming it themselves, without having to ask a chip manufacturer to design and produce a dedicated integrated circuit chip. Moreover, nowadays, instead of manually making integrated circuit chips, this kind of programming is mostly implemented by "logic compiler" software, which is similar to the software compiler used when developing and writing programs, and the original code before compilation must also be written in a specific programming language, which is called hardware description language (HDL). There is not only one HDL, but many kinds, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used ones are VHDL (Very-High-Speed ​​Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should also know that it is only necessary to program the method flow slightly in the above-mentioned hardware description languages ​​and program it into the integrated circuit, and then it is easy to obtain the hardware circuit that implements the logic method flow.

[0120] The controller can be implemented in any appropriate manner, for example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing a computer-readable program code (such as software or firmware) that can be executed by the (micro)processor, a logic gate, a switch, an application-specific integrated circuit (ASIC), a programmable logic controller, and an embedded microcontroller. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art also know that in addition to implementing the controller in a purely computer-readable program code manner, the controller can be implemented in the form of a logic gate, a switch, an application-specific integrated circuit, a programmable logic controller, and an embedded microcontroller by logically programming the method steps. Therefore, this controller can be considered as a hardware component, and the devices included therein for implementing various functions can also be regarded as structures within the hardware component. Or even, the devices for implementing various functions can be regarded as both software modules for implementing the method and structures within the hardware component.

[0121] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.

[0122] For the convenience of description, the above device is described in various units according to their functions. Of course, when implementing this specification, the functions of each unit can be implemented in the same or multiple software and / or hardware.

[0123] Those skilled in the art will appreciate that the embodiments of this specification may be provided as methods, systems, or computer program products. Therefore, this specification may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.

[0124] This specification is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of this specification. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0125] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0126] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0127] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0128] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0129] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.

[0130] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0131] Those skilled in the art will appreciate that the embodiments of this specification may be provided as methods, systems or computer program products. Therefore, this specification may take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware. Moreover, this specification may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0132] This specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. This specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.

[0133] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0134] The above description is only an embodiment of the present specification and is not intended to limit the present specification. For those skilled in the art, the present specification may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present specification shall be included in the scope of the claims of the present specification.

Claims

1. A data acquisition method, It is characterized in that include: In response to a user's data crawling request, determine the page to be crawled and the type of data to be crawled; Determine a crawler script that matches the data type to be crawled from the stored crawler scripts, crawl data of the page to be crawled by using the matching crawler script, and store the crawling result, which includes at least page data and page structure; According to the preset rules corresponding to the data type to be captured and the page data, determining whether the page data is abnormal; If yes, the matching crawler script and the page structure are input into the trained optimization model to obtain an optimized crawler script; Re-crawl data of the to-be-crawled page according to the optimized crawler script; If not, subsequent services are performed according to the page data.

2. The method according to claim 1, It is characterized in that The trained optimization model includes an analysis sub-model and an update sub-model; Inputting the matched crawler script and the page structure into the trained optimization model to obtain an optimized crawler script, specifically including: Inputting the matched crawler script and the page structure into the analysis sub-model to obtain abnormal factors output by the analysis sub-model; The abnormal factors and the matching crawler script are input into the update sub-model to obtain an optimized crawler script output by the update sub-model.

3. The method according to claim 2, It is characterized in that The optimization model is trained using the following method, wherein: For each data type to be captured, determine the historical versions of the crawler script that match the data type, the page structures captured by each historical version, and the optimization model to be trained; For each historical version, the historical version and the page structure captured by the historical version are used as training samples, and the iterative version of the historical version is determined, as well as the abnormal factors captured by the historical version; Inputting the training sample into the analysis sub-model in the optimization model to be trained, and obtaining the abnormal factors output by the analysis sub-model in the optimization model to be trained; According to the abnormal factors in the page structure captured by the historical version and the differences between the abnormal factors outputted, training the analysis sub-model in the optimization model to be trained; Input the output abnormal factors and the historical version into the update sub-model in the optimization model to be trained, and output an updated version of the historical version; According to the difference between the updated version and the iterative version of the historical version, the updated sub-model in the optimization model to be trained is trained.

4. The method according to claim 1, It is characterized in that The method further comprises: Determine the historical crawling results of the page to be crawled from the historical crawling results of the page to be crawled; Determine the target time for data crawling on the page to be crawled according to the crawling time of the normal historical crawling results of the page data; According to the target time, data is crawled on the to-be-crawled page through the matching crawler script.

5. The method according to claim 1, It is characterized in that The crawling result also includes a page status code; Before determining whether the page data is abnormal based on the preset rules corresponding to the data type to be captured and the page data, the method further includes: Determine whether the page status code in the crawling result matches the preset abnormal status code; If so, an abnormality warning is returned to the user, where the abnormality warning is used to prompt that the data of the page to be crawled is abnormal.

6. The method according to claim 5, It is characterized in that Return an abnormal warning to the user, specifically including: After a preset time, according to the matched crawler script, continue to crawl data on the to-be-crawled page, and determine whether the page status code in the crawling result matches the preset abnormal status code; If yes, an alarm phone number is returned to the user, where the alarm phone number is used to prompt the user that data capture has failed; If not, a warning email is returned to the user, where the warning email is used to prompt the user that the history crawling is abnormal.

7. The method according to claim 1, It is characterized in that Before storing the crawling result, the method further includes: Determine the time taken by the matching crawler script to crawl the page to be crawled; According to the crawling time consumption, determining whether the crawling time consumption is greater than a preset time consumption; If so, after a preset time interval, continue to crawl data on the page to be crawled through the matching crawler script.

8. A data acquisition device, It is characterized in that include: A determination module, used to determine the page to be crawled and the type of data to be crawled in response to the user's data crawling request; A crawling module, used to determine a crawler script matching the data type to be crawled from the stored crawler scripts, crawl data of the page to be crawled through the matching crawler script, and store the crawling results, which at least include page data and page structure; A judgment module, used for judging whether the page data is abnormal according to a preset rule corresponding to the data type to be captured and the page data; If so, the matching crawler script and the page structure are input into the trained optimization model to obtain an optimized crawler script; according to the optimized crawler script, data of the page to be crawled is crawled again; if not, subsequent business is executed according to the page data.

9. A computer-readable storage medium, It is characterized in that The storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the program, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Cited By

  • Self-adaptive data acquisition method and device

    CN120386907A

  • An adaptive data acquisition method and device

    CN120386907B