Webpage data acquisition method and system based on dynamic configuration

By configuring an independent proxy pool and dynamic configuration mechanism for each website, it solves the problem of repeatedly developing codes to crawl data from similar websites, achieves efficient and stable web page data acquisition, and reduces development costs and waste of IP resources.

CN118606536APending Publication Date: 2024-09-06SUZHOU JINZHIQU INFORMATION TECH CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

In the existing technology, crawling data for similar websites requires repeated development of a large amount of code, which is highly efficient and low-cost. Moreover, valid IPs are discarded because a single website blocks IPs, resulting in serious waste of resources.

Method used

Adopt a web page data acquisition method based on dynamic configuration, configure an independent proxy pool for each website, and use Redis and MongoDB for URL management and data storage to dynamically detect changes in configuration information and re-execute crawling tasks to avoid repeated development and IP Waste of resources.

Benefits of technology

It reduces development workload and later maintenance costs, optimizes the use of proxy IP resources, improves crawling efficiency and stability, and can quickly adapt to changes in website structure or new crawling tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118606536A
    Figure CN118606536A
Patent Text Reader

Abstract

The invention discloses a webpage data acquisition method and system based on dynamic configuration. The webpage data acquisition method comprises the following steps: S1, acquiring basic configuration information; s2, for each crawling object website, calling a corresponding agent pool interface, and downloading list page data of the crawling object website according to a root url of the crawling object website; s3, according to the list page data of each crawling object website, obtaining webpage data of each crawling object website; s4, according to the webpage data of each crawling object website, obtaining expected data by using a text information extraction strategy; and S5, dynamically detecting whether the configuration information used for indicating the crawling object website in the basic configuration information or the analysis class corresponding to the configuration information changes or not, and when the configuration information changes, executing the step S1 again. Through the expansion and updating mechanism of the dynamic configuration of the basic configuration information, repeated code development is avoided, and the development workload and the later maintenance cost are reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of computer network crawlers, and in particular to a web page data acquisition method based on dynamic configuration and a system thereof. Background Art

[0002] With the continuous development of Internet technology, network information is fragmented and the amount of information is growing exponentially. How can people quickly extract effective information from massive amounts of information? Using crawler technology to obtain web page data has become an effective way.

[0003] Under the existing technology, crawling data from similar websites requires repeated development of a large amount of code, which is inefficient and low-cost. Therefore, there is an urgent need for a web page data acquisition method and system based on dynamic configuration to solve the above technical problems. Summary of the invention

[0004] The present invention provides a web page data acquisition method and system based on dynamic configuration, which are used to solve the problem that crawling data from similar websites requires repeated development of a large amount of code, which is inefficient and low-cost.

[0005] To achieve the above objectives, this application is implemented through the following technical solutions:

[0006] The present application provides a web page data acquisition method based on dynamic configuration, and the web page data acquisition method comprises:

[0007] S1, obtaining basic configuration information; the basic configuration information includes website configuration information and system environment configuration information of each crawling target website;

[0008] S2, for each crawling target website, calling its corresponding proxy pool interface, and downloading the list page data of the crawling target website according to the root URL of the crawling target website, the list page data including the detail page URL pointing to each detail page of the crawling target website;

[0009] S3, obtaining web page data of each crawling target website according to the list page data of each crawling target website;

[0010] S4, according to the web page data of each crawling target website, using the text information extraction strategy to obtain the expected data;

[0011] S5, dynamically detect whether the configuration information for indicating the crawl target website in the basic configuration information or its corresponding parsing class has changed, and re-execute S1 if it has changed.

[0012] In one embodiment, calling the corresponding proxy pool interface and downloading the list page data of the crawl object website according to the root URL of the crawl object website includes:

[0013] Obtaining the proxy pool corresponding to the crawl target website and using it as the target proxy pool, wherein the proxy pools corresponding to different crawl target websites are independent of each other;

[0014] Call the interface of the target proxy pool to obtain an IP address for downloading list page data;

[0015] When the acquired IP is invalid for the crawling target website, it is deleted from the target proxy pool.

[0016] In one embodiment, the step of obtaining web page data of each crawling target website according to the list page data of each crawling target website includes:

[0017] For each crawled target website, save the URLs of each detail page extracted based on the list page data into the uncrawled key;

[0018] Get the web page data of each crawling target website according to the detail page URL in the uncrawled key of each crawling target website, save the crawled URL to the crawled key, and save the failed URL to the failed crawling key;

[0019] End the crawling when the URLs in the uncrawled keys of all crawled target websites are empty;

[0020] Among them, the uncrawled keys, crawled keys and failed crawling keys of each crawled object website are regarded as a key set, and the key sets of each crawled object website are isolated from each other and saved in redis.

[0021] In one embodiment, the text information extraction strategy includes:

[0022] Using a preset parsing method to obtain text information; the preset parsing method includes one or more combinations of BeautifulSoup, PyQuery, Scrapy and regular expressions; cleaning and processing the text information to obtain the expected data;

[0023] The method further includes: storing the text data in the expected data in a mongodb database via a memory.

[0024] In one of the embodiments, when an abnormality occurs in any step from step S1 to step S4, a monitoring alarm is activated and the abnormal location is recorded; when the abnormality is eliminated, the crawling of web page data continues from the abnormal location.

[0025] The present application also provides a web page data acquisition system based on dynamic configuration, the system comprising:

[0026] A configuration management module, wherein the configuration management module is used to configure basic configuration information of each crawling target website, wherein the basic configuration information includes website configuration information and system environment configuration information of each crawling target website;

[0027] A main startup module, the main startup module is used to generate a scheduling control instruction;

[0028] A scheduling task module, the scheduling task module is used to execute the task of crawling web page data according to the scheduling control instruction;

[0029] The webpage data crawling task includes:

[0030] S1, obtain basic configuration information;

[0031] S2, for each crawling target website, calling its corresponding proxy pool interface, and downloading the list page data of the crawling target website according to the root URL of the crawling target website, the list page data including the detail page URL pointing to each detail page of the crawling target website;

[0032] S3, obtaining web page data of each crawling target website according to the list page data of each crawling target website;

[0033] S4, according to the web page data of each crawling target website, using the text information extraction strategy to obtain the expected data;

[0034] S5, dynamically detect whether the configuration information for indicating the crawl target website in the basic configuration information or its corresponding parsing class has changed, and re-execute S1 if it has changed.

[0035] In one embodiment, the system further comprises:

[0036] An agent pool IP module, the agent pool IP module is used to maintain and provide agent pool IPs of each target agent pool;

[0037] The download management module is used to call the interface of the target proxy pool of each crawling object website and obtain an IP for downloading the list page data of the crawling object website.

[0038] In one embodiment, the system further comprises:

[0039] The url management module is used to save the URLs of each detail page extracted according to the list page data into the uncrawled key of redis for each crawled object website, save the URLs that have been crawled into the crawled key, and save the URLs that failed to crawl into the failed crawling key.

[0040] In one of the embodiments, the download management module is further used to obtain web page data of each crawling target website according to the list page data of each crawling target website;

[0041] The system further comprises a parsing management module, the parsing management module being used to obtain expected data from the webpage data downloaded by the download management module by using a text information extraction strategy;

[0042] The text information extraction strategy includes:

[0043] The text information is obtained by using a preset parsing method; the preset parsing method includes one or more combinations of BeautifulSoup, PyQuery, Scrapy and regular expressions; the text information is cleaned and processed to obtain the expected data.

[0044] In one embodiment, the system further comprises:

[0045] A storage management module, which is used to persistently store the expected data obtained by the analysis management module in a mongodb database, and at the same time, treat the uncrawled keys, crawled keys and failed crawling keys of each crawled object website as a key set, isolate the key sets of each crawled object website from each other and save them in redis;

[0046] The monitoring and alarm module is used to start the monitoring alarm and record the abnormal position when the task of crawling web page data is executed abnormally; when the system is restarted, the crawling of web page data will continue from the abnormal position.

[0047] The beneficial effects brought about by the technical solution provided by the present application are as follows: on the one hand, by configuring an independent proxy pool for each website and isolating different proxy pools from each other, the discarding of valid IPs due to the blocking of IPs by a single website is avoided, thereby reducing the waste of IP resources; on the other hand, when the configuration information or its corresponding parsing class changes, the acquisition of basic configuration information is re-executed, and website data crawling is performed based on the updated basic configuration information, that is, it can quickly adapt to changes in website structure or new crawling tasks, avoiding repeated code development, and reducing development workload and subsequent maintenance costs.

[0048] In summary, the dynamic configuration expansion and update mechanism of basic configuration information avoids repeated code development, reduces development workload and subsequent maintenance costs. By configuring an independent proxy pool for each crawling target website, it avoids the discarding of valid IPs due to the blocking of IPs by a single website, and optimizes the utilization of proxy IP resources through mutual isolation between different proxy pools. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] The present application is further described below in conjunction with the accompanying drawings and embodiments.

[0050] Figure 1 A schematic flow chart of a method for acquiring web page data based on dynamic configuration provided in an embodiment of the present application is shown.

[0051] Figure 2 A schematic diagram of a process of downloading list page data provided in an embodiment of the present application is shown.

[0052] Figure 3 A schematic diagram of a process for obtaining web page data provided by an embodiment of the present application is shown.

[0053] Figure 4 A schematic flow chart of another method for acquiring web page data based on dynamic configuration provided in an embodiment of the present application is shown.

[0054] Figure 5 A structural schematic diagram of a web page data acquisition system provided in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0055] In order to facilitate the understanding of the present invention, the present invention will be described more fully below with reference to the relevant drawings. Preferred embodiments of the present invention are provided in the drawings. However, the present invention can be implemented in many other different forms and is not limited to the embodiments described herein. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present invention more thorough and comprehensive.

[0056] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used herein in the specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. The term "and / or" used herein includes any and all combinations of one or more related listed items.

[0057] Computer web crawlers, referred to as web crawlers or crawlers for short, are a technology for automatically browsing Internet resources, automatically requesting web page content according to predetermined rules, and parsing web page content to extract useful information. Web crawlers can automatically perform tasks without human intervention. The main purpose is to extract information from web pages, such as text, pictures, links, etc. Through the network link structure, you can jump from one page of the crawl object website to another page, and traverse the entire web page data of the crawl object website through the traversal mechanism. In specific operations, you can simulate a browser or other client through a user agent and send a request to the website server. The web page data acquisition mentioned in this application refers to following the crawler protocol Robots to crawl the allowed search website as the crawl object website.

[0058] Redis is an open source log-based, key-value database written in ANSI C, supporting networks, and can be both memory-based and persistent. MongoDB is a distributed document storage database.

[0059] In the related art, taking the information crawling method of a distributed web crawler disclosed in application number CN201711478979.3 as an example, it discloses that the web URL is crawled by using multiple IPs obtained at the same time, and the crawled URL is encoded as a key value and stored in a redis cluster; multiple crawler clients simultaneously obtain URLs from the redis cluster, and parse the target information from the obtained URLs. The information crawling method provided by it uses multiple devices to collaborate with multiple IPs, and crawls all URLs on the Internet at the same time, so as to obtain useful information from a large number of network resources better, faster and more accurately. However, like other crawler technologies, when using dynamic IP, all websites share a proxy pool IP, that is, if an IP is blocked by a website, even if the IP is still available to other websites, the IP will be directly discarded, without considering the isolation between proxy pools of different websites. At the same time, the related technology does not solve the problem that crawling data for similar websites requires repeated development of a large amount of code, and the efficiency is low and high.

[0060] The present application provides a web page data acquisition method based on dynamic configuration and a system thereof. The following will first describe an embodiment of the method and then describe the system.

[0061] Method embodiment.

[0062] See also Figure 1 , Figure 1 A schematic flow chart of a method for acquiring web page data based on dynamic configuration provided in an embodiment of the present application is shown.

[0063] This embodiment provides a web page data acquisition method based on dynamic configuration, and the web page data acquisition method includes S101 to S105.

[0064] S101, obtaining basic configuration information, wherein the basic configuration information is obtained by using a preprocessor to parse a configuration system, and the basic configuration information includes website configuration information and system environment configuration information of each crawling target website;

[0065] The preprocessor can be used to parse the website's configuration file to obtain basic configuration information. The basic configuration information includes the website-specific configuration (website configuration information) for each crawled target website and the system environment configuration information of the entire crawler system. The system environment configuration information can include redis database configuration information, mongodb database configuration information, configuration information for obtaining the proxy pool IP, etc. The website configuration information includes the root URL of each crawled target website.

[0066] S102, for each crawling target website, calling its corresponding proxy pool interface, and downloading the list page data of the crawling target website according to the root URL of the crawling target website, the list page data including the detail page URL pointing to each detail page of the crawling target website;

[0067] For each crawled object website, call the interface of its corresponding proxy pool to obtain the proxy IP used to download the list page, ensuring that each crawled object website uses an independent proxy pool. Use the obtained proxy IP to download the list page data of the crawled object website. The list page data usually contains a URL link to the details page. It can be considered that the proxy pools (IPs) of different crawled object websites are isolated from each other to solve the problem of poor isolation when all websites share a proxy pool, resulting in an IP being blocked and cannot be used for other websites.

[0068] S103, acquiring web page data of each crawling target website according to the list page data of each crawling target website;

[0069] Specifically, the detail page URL can be extracted from the list page data to further crawl the web page data of the target website.

[0070] S104, obtaining expected data using a text information extraction strategy based on web page data of each crawling target website;

[0071] S105, dynamically detecting whether the configuration information for indicating the crawl target website in the basic configuration information or the corresponding parsing class has changed, and re-executing S101 if it has changed.

[0072] Monitor in real time whether the basic configuration information has changed. The change of the basic configuration information includes the change of the configuration information of the crawling target website or its corresponding parsing class. Once the change is detected, restart the execution from step S101 to ensure the latest status of the basic configuration information. Step S105 can be performed after step S101, and can be performed in parallel with any step after step S101.

[0073] Therefore, compared with the situation in the related art that if an IP is banned by a crawl target website, all crawl target websites will no longer be used, and crawling data for similar websites requires repeated development of a large amount of code, which is inefficient and low-cost. The technical solution provided by this embodiment, on the one hand, by configuring an independent proxy pool for each website and isolating different proxy pools from each other, avoids the discarding of valid IPs due to the banning of IPs by a single website, thereby reducing the waste of IP resources; on the other hand, when the configuration information or its corresponding parsing class changes, the basic configuration information is obtained again, and the website data is crawled according to the updated basic configuration information. When the website structure changes, only the configuration information needs to be updated without modifying and testing a large amount of code. In other words, it can quickly adapt to changes in the website structure or the addition of new crawling tasks, avoiding repeated code development and reducing development workload and subsequent maintenance costs.

[0074] In summary, this embodiment provides a mechanism for expanding and updating the basic configuration information of dynamic configuration. As long as the configuration information used to indicate the crawling target website is newly added to the basic configuration information or the corresponding parsing class is adjusted, the web page data can be acquired again, realizing the implementation method of dynamically configuring and expanding the acquisition of web page data, avoiding repeated code development, reducing development workload and subsequent maintenance costs. By configuring an independent proxy pool for each crawling target website, the discarding of valid IPs due to the blocking of IPs by a single website is avoided, and the utilization of proxy IP resources is optimized through the mutual isolation between different proxy pools.

[0075] See also Figure 2 , Figure 2 A schematic diagram of a process of downloading list page data provided in an embodiment of the present application is shown.

[0076] In one of the embodiments, calling the corresponding proxy pool interface and downloading the list page data of the crawl object website according to the root URL of the crawl object website includes S201 to S203.

[0077] S201, obtaining a proxy pool corresponding to the crawl target website and using it as a target proxy pool, wherein the proxy pools corresponding to different crawl target websites are independent of each other;

[0078] First, determine a corresponding proxy pool for each crawling target website to ensure that the proxy IP pools of different websites are independent of each other.

[0079] S202, calling the interface of the target proxy pool to obtain an IP address for downloading list page data;

[0080] Call the interface of the target proxy pool and obtain a proxy IP from the proxy pool. The proxy IP will be used to initiate HTTP requests to the crawled object website, download list page data, and other operations.

[0081] S203, when the acquired IP is invalid for the crawling target website, delete it from the target proxy pool.

[0082] Use the obtained proxy IP to download the list page data and check the validity of the IP. If the proxy IP fails to download data or is blocked by the website, mark the IP as invalid and delete it from the target proxy pool.

[0083] By using proxy IP, the success rate and efficiency of crawling can be improved to a certain extent. The proxy pool of each crawling target website is managed independently, so that the crawling problem of one crawling target website will not affect the crawling tasks of other crawling target websites, and the overall robustness of the web page data acquisition method is enhanced. By timely deleting invalid proxy IPs from the corresponding proxy pool of the crawling target website, the reuse of invalid proxies is avoided and the efficiency of the use of proxy resources is optimized. This technical solution can be used in large-scale distributed crawler systems, which can handle a large number of crawling tasks while maintaining efficient proxy IP management.

[0084] At the same time, when a new crawling target website needs to be added, it is only necessary to allocate a new proxy pool for it without making large-scale adjustments to the existing proxy pool.

[0085] In summary, this technical solution improves the efficiency and stability of web crawlers in the process of data capture, and reduces the problems caused by proxy IP failure through intelligent proxy IP management.

[0086] See also Figure 3 , Figure 3 A schematic diagram of a process for obtaining web page data provided by an embodiment of the present application is shown.

[0087] In one embodiment, the process of obtaining web page data of each crawling target website according to the list page data of each crawling target website includes S301 to S303.

[0088] S301, for each crawled target website, save each detail page URL extracted according to the list page data into the uncrawled key;

[0089] The list page data of each crawled object website can be parsed, and the URL of the detail page can be extracted as the detail page URL. The detail page URL is then stored in the Redis database and associated with the uncrawled key, which indicates the set of URLs that have not been crawled. Redis's caching capabilities can be used to quickly store and retrieve subset URLs, improving the efficiency of data processing.

[0090] S302, obtaining web page data of each crawling target website according to the detail page URL in the uncrawled key of each crawling target website, saving the crawled URL to the crawled key, and saving the crawled failed URL to the failed crawling key;

[0091] In specific applications, you can traverse the uncrawled keys stored in Redis, get the detail page URL from them, and initiate an HTTP request to crawl the corresponding web page data. After the crawl is successful, the detail page URL is removed from the uncrawled key and stored in the crawled key. If the crawl fails, the detail page URL will be moved to the failed crawl key, which can be used for subsequent retries or analysis.

[0092] S303, when the URLs in the un-crawled keys of all crawled target websites are empty, the crawling is terminated. When the un-crawled keys of all crawled target websites in Redis are empty, that is, there are no remaining URLs to be crawled, the current crawling task is terminated.

[0093] Among them, the uncrawled keys, crawled keys, and failed crawling keys of each crawling target website are regarded as a key set, and the key sets of each crawling target website are isolated from each other and saved in redis. It can be considered that each crawling target website corresponds to independent uncrawled keys, crawled keys, and failed crawling keys in Redis, and these keys are isolated from each other.

[0094] Therefore, by utilizing the high-speed read and write characteristics of Redis, a large amount of URL data can be efficiently managed, speeding up the data crawling process. By distinguishing between URLs that have not been crawled, crawled, and failed to crawl, detailed tracking and management capabilities for crawling tasks are provided. The design of the crawled key ensures that once the detail page URL is successfully crawled, it will not be accessed again, avoiding waste of resources.

[0095] Furthermore, failed URLs are stored in a failed crawl key, allowing these URLs to be retried, improving the integrity of data crawling.

[0096] In one embodiment, the text information extraction strategy includes:

[0097] Use the preset parsing method to obtain text information; the preset parsing method includes one or more combinations of BeautifulSoup, PyQuery, Scrapy and regular expressions;

[0098] The text information is cleaned and processed to obtain the expected data.

[0099] The method further comprises:

[0100] The text data in the expected data is stored in the MongoDB database through the memory.

[0101] The text information is cleaned and processed. Data cleaning refers to removing useless non-text content such as HTML tags, JavaScript codes, CSS styles, and cleaning extra spaces, line breaks, special characters, etc. to standardize the text format. Processing refers to correcting or unifying errors or inconsistencies in the text, such as date formats, currency symbols, etc. Processing can also include operations such as removing or replacing sensitive information and standardizing synonyms.

[0102] At the same time, MongoDB's flexible document storage structure is used to facilitate the storage of structured or semi-structured text data.

[0103] In one of the embodiments, when an abnormality occurs in any step from step S101 to step S104, a monitoring alarm is activated and the abnormal location is recorded; when the abnormality is eliminated, the crawling of web page data continues from the abnormal location.

[0104] In each step (S101 to S104) of executing web page data acquisition, possible abnormal situations are monitored in real time. Once an abnormality is detected in any step, the monitoring alarm can be automatically started to alert the system administrator or developer to the abnormal situation. At the same time, the specific location where the abnormality occurs will be recorded, that is, the specific location of the crawler operation to the crawl object website. In specific applications, the system administrator or developer can analyze and handle the abnormality based on the alarm information and the recorded abnormal location. Once the abnormality is eliminated, the system can be restarted and the web page data crawling task can be continued from the recorded abnormal location. In other words, a recovery mechanism can be provided to resume execution from the last stop, including re-acquiring the proxy IP, re-downloading the page, or re-parsing the data.

[0105] Therefore, when a problem occurs, progress can be continued from the last breakpoint without losing progress, ensuring the continuity and reliability of data crawling. The abnormal location is clearly recorded to facilitate system administrators or developers to quickly locate the problem, improving the efficiency of system maintenance.

[0106] See also Figure 4 , Figure 4 A schematic flow chart of another method for acquiring web page data based on dynamic configuration provided in an embodiment of the present application is shown.

[0107] In a specific application, a web page data acquisition method is provided, firstly, basic configuration information is acquired, and website configuration information of each crawling target website in the basic configuration information (website 1 configuration information, website 2 configuration information ... website N configuration information, N is a positive integer greater than 1) is used to crawl URLs according to the root URL (i.e., list page data is acquired, and the list page data includes detail page URLs pointing to each detail page of the crawling target website);

[0108] Save each URL to redis through the URL management module; download web pages (according to the list page data of each crawled object website), execute text information extraction strategy through the parsing class of each crawled object website (parsing class 1, parsing class 2...parsing class N correspond to website 1 configuration information, website 2 configuration information...website N configuration information respectively), store the URLs (completed and failed crawling) in redis, and store the text data in the expected data in the mongodb database.

[0109] The web page data acquisition method provided by the present application has the IP addresses of the proxy pools of different crawling object websites isolated from each other, and one proxy pool is provided for one crawling object website. At the same time, if the data structure characteristics and attributes extracted from a new website page are consistent with the implementation class pool of the existing crawling object website, there is no need to develop code, and only the website name and root URL need to be set through the configuration system; if the data structure characteristics and attributes extracted from a new website page are inconsistent with the implementation class pool of the existing website, only a parsing class code and configuration need to be added, and no other additional development costs are required. The method has good scalability, improves efficiency, and reduces enterprise costs. By dynamically monitoring the changes in basic configuration information, the web page data acquisition method has high scalability and flexibility. The URL information is stored in different keys in redis, and the URL collections of successful, failed, and uncrawled crawling of each website are stored. If it is paused or restarted at any time, it can continue to execute in the last paused state, and can be stopped and started at any time, with good flexibility and reliability.

[0110] System Embodiments.

[0111] See also Figure 5 , Figure 5 A structural schematic diagram of a web page data acquisition system provided in an embodiment of the present application is shown.

[0112] This embodiment provides a webpage data acquisition system based on dynamic configuration, which is used to implement the method in the method embodiment. Its specific implementation method is consistent with the implementation method and technical effects recorded in the above method embodiment, and some contents are not repeated here. The system includes:

[0113] A configuration management module, wherein the configuration management module is used to configure basic configuration information of each crawling target website, wherein the basic configuration information includes website configuration information and system environment configuration information of each crawling target website;

[0114] A main startup module, the main startup module is used to generate a scheduling control instruction;

[0115] A scheduling task module, the scheduling task module is used to execute the task of crawling web page data according to the scheduling control instruction;

[0116] The webpage data crawling task includes:

[0117] S101, obtaining basic configuration information;

[0118] S102, for each crawling target website, calling its corresponding proxy pool interface, and downloading the list page data of the crawling target website according to the root URL of the crawling target website, the list page data including the detail page URL pointing to each detail page of the crawling target website;

[0119] S103, acquiring web page data of each crawling target website according to the list page data of each crawling target website;

[0120] S104, obtaining expected data using a text information extraction strategy based on web page data of each crawling target website;

[0121] S105, dynamically detecting whether the configuration information for indicating the crawl target website in the basic configuration information or the corresponding parsing class has changed, and re-executing S101 if it has changed.

[0122] In specific applications, the scheduling task module is used to perform specific web crawling data tasks, which may include tasks for obtaining list page URLs (list page data), obtaining detail page URLs, obtaining detail page data, etc. Each scheduling task automatically loads the crawlers of all crawling target websites, and starts multi-threaded execution of each crawler's task of obtaining web page data without affecting each other.

[0123] In one embodiment, the system further comprises:

[0124] An agent pool IP module, the agent pool IP module is used to maintain and provide agent pool IPs of each target agent pool;

[0125] The download management module is used to call the interface of the target proxy pool of each crawling object website and obtain an IP for downloading the list page data of the crawling object website.

[0126] In one embodiment, the system further comprises:

[0127] The url management module is used to save the URLs of each detail page extracted according to the list page data into the uncrawled key of redis for each crawled object website, save the URLs that have been crawled into the crawled key, and save the URLs that failed to crawl into the failed crawling key.

[0128] Among them, the url management module can be applied to the above-mentioned web page data acquisition method, combined with basic configuration information, to solve the problem that the crawler operation device can only crawl web page data from the beginning after being paused and restarted, and cannot start from the pause point, resulting in poor flexibility.

[0129] In one of the embodiments, the download management module is further used to obtain web page data of each crawling target website according to the list page data of each crawling target website;

[0130] The system further comprises a parsing management module, the parsing management module being used to obtain expected data from the webpage data downloaded by the download management module by using a text information extraction strategy;

[0131] The text information extraction strategy includes:

[0132] Use the preset parsing method to obtain text information; the preset parsing method includes one or more combinations of BeautifulSoup, PyQuery, Scrapy and regular expressions;

[0133] The text information is cleaned and processed to obtain the expected data;

[0134] The method further includes: storing the text data in the expected data in a mongodb database via a memory.

[0135] In one embodiment, the system further comprises:

[0136] A storage management module, which is used to persistently store the expected data obtained by the analysis management module in a mongodb database, and at the same time, treat the uncrawled keys, crawled keys and failed crawling keys of each crawled object website as a key set, isolate the key sets of each crawled object website from each other and save them in redis;

[0137] The monitoring and alarm module is used to start the monitoring alarm and record the abnormal position when the task of crawling web page data is executed abnormally; when the system is restarted, the crawling of web page data will continue from the abnormal position.

[0138] Execution anomalies refer to detecting abnormal situations through preset rules, such as request failure, timeout, data format error, parsing error, etc. Once an anomaly is detected, the monitoring alarm module will automatically trigger an alarm according to the preset alarm strategy and send a notification to the system administrator or developer. Alarms can be notified in a variety of ways, such as email, SMS, instant messaging tools (such as Slack, Telegram), system log records, etc. Alarm information can include details such as the type of anomaly and the time of occurrence.

[0139] The technical features of the above-described embodiments can be combined arbitrarily. In order to make the description concise, all possible combinations of the technical features in the above-described embodiments are not described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification. The above-described embodiments only express several implementation methods of the present invention, and their descriptions are relatively specific and detailed, but they cannot be understood as limiting the scope of the patent application. It should be pointed out that for ordinary technicians in this field, without departing from the concept of the present invention, several variations and improvements can be made, which all belong to the protection scope of the present invention. Therefore, the protection scope of the patent of the present invention shall be based on the attached claims.

Claims

1. A web page data acquisition method based on dynamic configuration, characterized in that: The web page data acquisition method comprises: S1, obtaining basic configuration information; the basic configuration information includes website configuration information and system environment configuration information of each crawling target website; S2, for each crawling target website, calling its corresponding proxy pool interface, and downloading the list page data of the crawling target website according to the root URL of the crawling target website, the list page data including the detail page URL pointing to each detail page of the crawling target website; S3, obtaining web page data of each crawling target website according to the list page data of each crawling target website; S4, according to the web page data of each crawling target website, using the text information extraction strategy to obtain the expected data; S5, dynamically detect whether the configuration information for indicating the crawl target website in the basic configuration information or its corresponding parsing class has changed, and re-execute S1 if it has changed.

2. A webpage data acquisition method based on dynamic configuration according to claim 1, characterized in that: The calling of the corresponding proxy pool interface and downloading the list page data of the crawl object website according to the root URL of the crawl object website includes: Obtaining the proxy pool corresponding to the crawl target website and using it as the target proxy pool, wherein the proxy pools corresponding to different crawl target websites are independent of each other; Call the interface of the target proxy pool to obtain an IP address for downloading list page data; When the acquired IP is invalid for the crawling target website, it is deleted from the target proxy pool.

3. A webpage data acquisition method based on dynamic configuration according to claim 2, characterized in that: The step of obtaining web page data of each crawling target website according to the list page data of each crawling target website includes: For each crawled target website, save the URLs of each detail page extracted based on the list page data into the uncrawled key; Get the web page data of each crawling target website according to the detail page URL in the uncrawled key of each crawling target website, save the crawled URL to the crawled key, and save the failed URL to the failed crawling key; End the crawling when the URLs in the uncrawled keys of all crawled target websites are empty; Among them, the uncrawled keys, crawled keys and failed crawling keys of each crawled object website are regarded as a key set, and the key sets of each crawled object website are isolated from each other and saved in redis.

4. The webpage data acquisition method based on dynamic configuration according to claim 1, characterized in that: The text information extraction strategy includes: Use the preset parsing method to obtain text information; the preset parsing method includes one or more combinations of BeautifulSoup, PyQuery, Scrapy and regular expressions; The text information is cleaned and processed to obtain the expected data; The method further includes: storing the text data in the expected data in a mongodb database via a memory.

5. The webpage data acquisition method based on dynamic configuration according to claim 1, characterized in that: When an abnormality occurs in any step from step S1 to step S4, the monitoring alarm is activated and the abnormal position is recorded; when the abnormality is eliminated, the crawling of web page data continues from the abnormal position.

6. A web page data acquisition system based on dynamic configuration, characterized in that: The system comprises: A configuration management module, wherein the configuration management module is used to configure basic configuration information of each crawling target website, wherein the basic configuration information includes website configuration information and system environment configuration information of each crawling target website; A main startup module, the main startup module is used to generate a scheduling control instruction; A scheduling task module, the scheduling task module is used to execute the task of crawling web page data according to the scheduling control instruction; The webpage data crawling task includes: S1, obtain basic configuration information; S2, for each crawling target website, calling its corresponding proxy pool interface, and downloading the list page data of the crawling target website according to the root URL of the crawling target website, the list page data including the detail page URL pointing to each detail page of the crawling target website; S3, obtaining web page data of each crawling target website according to the list page data of each crawling target website; S4, according to the web page data of each crawling target website, using the text information extraction strategy to obtain the expected data; S5, dynamically detect whether the configuration information for indicating the crawl target website in the basic configuration information or its corresponding parsing class has changed, and re-execute S1 if it has changed.

7. The webpage data acquisition system based on dynamic configuration according to claim 6, characterized in that: The system further comprises: An agent pool IP module, the agent pool IP module is used to maintain and provide agent pool IPs of each target agent pool; The download management module is used to call the interface of the target proxy pool of each crawling object website and obtain an IP for downloading the list page data of the crawling object website.

8. The webpage data acquisition system based on dynamic configuration according to claim 7, characterized in that: The system further comprises: The url management module is used to save the URLs of each detail page extracted according to the list page data into the uncrawled key of redis for each crawled object website, save the URLs that have been crawled into the crawled key, and save the URLs that failed to crawl into the failed crawling key.

9. The webpage data acquisition system based on dynamic configuration according to claim 8, characterized in that: The download management module is also used to obtain web page data of each crawling target website according to the list page data of each crawling target website; The system further comprises a parsing management module, the parsing management module being used to obtain expected data from the webpage data downloaded by the download management module by using a text information extraction strategy; The text information extraction strategy includes: The text information is obtained by using a preset parsing method; the preset parsing method includes one or more combinations of BeautifulSoup, PyQuery, Scrapy and regular expressions; the text information is cleaned and processed to obtain the expected data.

10. The webpage data acquisition system based on dynamic configuration according to claim 9, characterized in that: The system further comprises: A storage management module, which is used to persistently store the expected data obtained by the analysis management module in a mongodb database, and at the same time, treat the uncrawled keys, crawled keys and failed crawling keys of each crawled object website as a key set, isolate the key sets of each crawled object website from each other and save them in redis; The monitoring and alarm module is used to start the monitoring alarm and record the abnormal position when the task of crawling web page data is executed abnormally; when the system is restarted, the crawling of web page data will continue from the abnormal position.

Citation Information

Patent Citations

  • Web page crawler method and device and electronic equipment

    CN108334585A

  • Method and device for obtaining web page information, and computer-readable medium

    CN109033195A

  • Webpage information processing method and system, electronic equipment and storage medium

    CN109597952A

  • Advertising-oriented master-slave distributed content crawling robot

    CN113656673A

  • Data crawling method and device, storage medium and electronic equipment

    CN113934912A