Data crawling method, system and computer-readable storage medium
Through the combination of Web client and server, data crawling tasks and crawling time intervals are dynamically configured, which solves the problems of low data crawling efficiency and poor flexibility in the existing technology, and realizes an efficient and flexible data extraction process.
Patent Information
- Application Number
- CN202410760744.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-13
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2044-06-13
AI Technical Summary
Existing web crawler technology is inefficient in the data crawling process, requires a lot of manpower to write code, and has poor flexibility, making it difficult to extract the information required by users from huge network information.
Provide a data crawling method and system. Through the combination of Web client and server, users can dynamically configure data crawling tasks on the Web client, including selecting crawling data sources and setting crawling time intervals. The server performs operations according to the configuration. Scheduled crawling reduces coding labor costs and improves efficiency and flexibility.
It realizes dynamic configuration and scheduled crawling of data crawling tasks, significantly improves the efficiency and flexibility of data crawling, reduces the labor cost of writing codes, and simplifies the data extraction process.
Smart Images

Figure CN118332174B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data acquisition technology, and in particular to a data crawling method, system and computer-readable storage medium. Background Art
[0002] With the rapid development of information network technology, the amount of network information has exploded. However, there is usually some redundant information or information that users do not pay attention to in the huge amount of network information. Therefore, it is necessary to obtain the information required by users from the huge amount of network information.
[0003] A web crawler (or crawler engine) is a program that automatically browses the web and crawls web page data. It can filter and crawl the information required by users from the web according to certain search strategies. Since web page data is relatively complex and the content is uneven, sometimes only a small part of the data needs to be crawled. In this case, R&D personnel have to write a lot of code to complete the crawling process of the web crawler. However, this way of writing code consumes a lot of manpower and the efficiency of data crawling is relatively low. Summary of the invention
[0004] The present application provides a data crawling method, system and computer-readable storage medium, which can improve the efficiency of data crawling.
[0005] In a first aspect, the present application provides a data crawling method, which is applied to a data crawling system, wherein the data crawling system includes a Web client and a server, and the method includes:
[0006] The Web client displays a first page, where the first page is used to configure a data crawling task;
[0007] The Web client receives a first configuration operation for the data crawling task through the first page, and sends the configuration content of the data crawling task to the server storage, wherein the first configuration operation at least includes the configuration of the crawling data source and crawling time interval of the data crawling task;
[0008] When the Web client receives the operation of starting the data crawling task, it sends a task request to the server to request the server to execute the data crawling task;
[0009] The server crawls web page data from the website corresponding to the crawl data source at a regular interval according to the crawl time interval.
[0010] The Web client and the server can communicate with each other. Users (such as R&D personnel) can log in to the Web client to access the Web management page and configure the data crawling task on the Web management page (that is, create a data crawling task). After the data crawling task is triggered on the Web client, the Web client can send the task request to the server, and the server can execute the data crawling task in the background and store the data crawling results.
[0011] When configuring a data crawling task on a Web client, the Web client may display a first page (i.e., a data crawling task management page), on which a user may configure information such as crawling data sources and crawling time intervals of the data crawling task, and may send the configuration content to a server for storage, for example, the server stores the configuration content of the data crawling task in a first data table. During the data crawling process on the server, web page data may be crawled regularly and continuously according to the configured crawling time interval.
[0012] In one implementation, if the user does not configure the crawling time interval of the data crawling task in the Web client, the server can set a default crawling time interval to crawl web page data regularly and continuously according to the crawling time interval.
[0013] Therefore, the above data crawling method can enable users to dynamically configure data crawling tasks on the Web client, reducing the labor cost of writing code. At the same time, the server can continuously perform the data crawling process according to the crawling time interval, which improves the efficiency of data crawling and also improves the flexibility of the data crawling process.
[0014] In combination with the first aspect, in some implementations of the first aspect, the first page includes a first control, and the Web client receives a first configuration operation for the data crawling task through the first page, including:
[0015] The Web client displays a first input control for configuring the data crawling task in response to a user clicking the first control;
[0016] The crawling data source and the crawling time interval input by the user on the first input control are received to complete the first configuration operation.
[0017] Among them, the first page may include a first control (i.e., a newly added control). After the user clicks the first control, the Web client may display a first input control for configuring the data crawling task, which may be used to enter the name, code, description, crawling data source, crawling time interval, etc. After filling in these configuration contents, the first configuration operation can be completed by saving. Thus, the user can complete the configuration of the data crawling task through a convenient web page configuration process, thereby improving the efficiency of data crawling.
[0018] In combination with the first aspect, in some implementations of the first aspect, after completing the first configuration operation, the method further includes:
[0019] The Web client displays the configuration content of the data crawling task and a second control on the first page, where the second control is used to trigger the start and stop of the data crawling task.
[0020] Among them, after completing the configuration of the data crawling task, the record of the configured data crawling task will be displayed on the above-mentioned first page of the Web client, and the record should correspond to a second control (i.e., an operation control) for triggering the start and stop of the task, and can also be used to trigger the editing of the data crawling task, i.e., changing some configuration content, etc.
[0021] Then correspondingly, the above-mentioned Web client receives the operation of starting the data crawling task, including: the Web client receives the user's click operation on the second control, triggering the start of the data crawling task.
[0022] As a result, users can trigger and start data crawling tasks with one click in the Web client, reducing the labor cost of writing code and improving efficiency.
[0023] In combination with the first aspect, in some implementations of the first aspect, the method further includes:
[0024] The Web client displays a second page, where the second page is used to configure the crawled data source;
[0025] The Web client receives a second configuration operation on the crawled data source through the second page, and sends the configuration content of the crawled data source to the server storage, wherein the second configuration operation at least includes the configuration of the URL corresponding to the crawled data source.
[0026] Because the user can configure the crawling data source of the data crawling task on the first page of the Web client, the crawling data source must be configured in advance for subsequent selection. When configuring the crawling data source (i.e., uniform resource location (URL) data source) on the Web client, the Web client can display a second page (i.e., URL management page), on which the user can configure the URL data source's website address and other information, and can send the configuration content to the server for storage, for example, the server stores the configuration content of the URL data source in the second data table.
[0027] As a result, users can dynamically configure crawled data sources on the Web client, reduce the labor cost of writing code, and improve the efficiency of data extraction.
[0028] In combination with the first aspect, in some implementations of the first aspect, the second page includes a third control, and the Web client receives a second configuration operation on the crawled data source through the second page, including:
[0029] The Web client displays a second input control for configuring the crawled data source in response to a user clicking the third control;
[0030] Receive the URL corresponding to the crawled data source input by the user on the second input control, and complete the second configuration operation.
[0031] Among them, the second page may include a third control (i.e., a new control). After the user clicks the third control, the Web client may display a second input control for configuring the crawled data source, which may be used to enter the name, code, description, URL, type, etc. After filling in these configuration contents, save to complete the above second configuration operation. Thus, the user can complete the configuration of the crawled data source through a convenient web page configuration process, thereby improving the efficiency of data crawling.
[0032] In combination with the first aspect, in some implementations of the first aspect, after completing the second configuration operation, the method further includes:
[0033] The Web client displays the configuration content of the crawled data source and a fourth control on the second page, where the fourth control is used to trigger the configuration of the crawling rules of the crawled data source.
[0034] Among them, after completing the configuration of the crawled data source, the record of the configured crawled data source will be displayed on the above-mentioned second page of the Web client, and the record should correspond to a fourth control (i.e., an operation control) for triggering operations such as editing, deleting, and extracting data (including configuration of crawling rules) on the crawled data source.
[0035] In combination with the first aspect, in some implementations of the first aspect, after the Web client displays the configuration content of the crawled data source and the fourth control on the second page, the method further includes:
[0036] The Web client receives a click operation on the fourth control by the user, and displays a third page for configuring the crawling rule;
[0037] receiving a click operation of the user on the fifth control on the third page, and acquiring and displaying original message information of the website address corresponding to the crawled data source;
[0038] Receive a regular expression input by the user on a third input control on the third page, and perform a crawling test on the original message information according to the regular expression.
[0039] Among them, if the user clicks on the data extraction in the fourth control, the Web client will display the third page for configuring the crawling rules, on which the fifth control (i.e., the original message acquisition control) is displayed. When the user clicks on the original message acquisition control, the Web client can send a request to the server, requesting the server to query the original message of the URL corresponding to the crawling data source, and display the data of the original message. At the same time, the third input control (i.e., the crawling rule input box) is also displayed on the third page, and the user can enter a rule expression on the third input control, for example, the rule expression can be a regular expression or XML path language. After entering the rule expression, you can click the crawl test control, that is, you can test the crawling of the original message according to the entered rule expression to test whether the entered rule expression is accurate. As a result, users can easily configure or update crawling rules on the Web client, reducing the labor cost of writing code.
[0040] In some implementations, after completing the configuration of the crawling rules on the Web client, the crawling rules and other information may also be sent to the server for storage, and the server may store the crawling rules configured for the crawling data source in the third data table.
[0041] In combination with the first aspect, in some implementations of the first aspect, the task request carries an identifier of the data crawling task, and after the Web client sends the task request to the server, the method further includes:
[0042] The server obtains the crawling data source corresponding to the data crawling task according to the identifier of the data crawling task, and stores the crawling data source and the crawling trigger time into a first queue, wherein the crawling trigger time is determined by the server according to the current system time and the crawling time interval.
[0043] Among them, after the above configuration of the data crawling task is completed, if the user triggers to start the data crawling task, the Web client will send a task request to the server, and the task request can carry the identifier corresponding to the data crawling task, so that the server can find the corresponding crawling data source and crawling data interval from the above first data table according to the identifier. In addition, the server can calculate the crawling trigger time according to the current system time and the crawling time interval, and store the crawling data source and crawling trigger time in the first queue (i.e., the queue to be crawled) for subsequent reading of the crawling data source from the first queue for data crawling.
[0044] It can be understood that the first queue may store crawling data sources corresponding to different data crawling tasks, and there may be multiple crawling data sources corresponding to one data crawling task.
[0045] In combination with the first aspect, in some implementations of the first aspect, the server periodically crawls web page data from the URL corresponding to the crawl data source according to the crawl time interval, including:
[0046] The server obtains the crawl data source from the first queue, and crawls the web page data according to the website corresponding to the crawl data source when the current system time reaches the crawl trigger time;
[0047] Deleting the information of the crawled data source from the first queue, and determining the next crawling trigger time of the crawled data source according to the crawling time interval;
[0048] The crawling data source and the next crawling trigger time are stored again in the first queue to crawl the web page data regularly.
[0049] Among them, in the process of data crawling, the server can first obtain a preset number of crawling data sources (i.e., as data sources to be crawled) from the above-mentioned first queue, and the preset number of crawling data sources includes the crawling data sources corresponding to the above-mentioned configured data crawling tasks. If the current system time reaches the crawling trigger time corresponding to the crawling data source, the server can crawl web page data according to the URL corresponding to the crawling data source. Afterwards, the server can delete the crawled crawling data source from the first queue, calculate the next crawling trigger time, and re-store the crawling data source and the next crawling trigger time into the first queue to realize the timed and continuous crawling of web page data and improve the efficiency of data crawling.
[0050] In some implementations, the server may save the crawled web page data to a storage medium for subsequent reading when needed.
[0051] In combination with the first aspect, in some implementations of the first aspect, the crawling rule includes a mandatory setting for fields included in the crawling results, and after obtaining the webpage data, the method further includes:
[0052] If the mandatory setting corresponding to the first field in the webpage data is mandatory, and the value of the first field is empty, the server discards the webpage data.
[0053] That is to say, when the user configures the crawling rules in the above-mentioned Web client, the user can also set the fields contained in the crawling results as mandatory. For example, if a certain field is set as a mandatory item, then if the mandatory setting corresponding to the first field (that is, any field) in the crawled web page data is mandatory, but the value of the first field is an empty value, indicating that the first field does not meet the requirements of the mandatory setting, the server can discard the web page data to ensure that the crawled web page data meets user needs.
[0054] In combination with the first aspect, in some implementations of the first aspect, crawling the webpage data according to the URL corresponding to the crawling data source includes:
[0055] The server obtains the crawling rules corresponding to the crawling data source;
[0056] The content in the website corresponding to the crawling data source is crawled according to the crawling rules to obtain the web page data.
[0057] Among them, because the above-mentioned server stores the crawling rules corresponding to the crawling data source in the third data table, the crawling rules corresponding to the crawling data source can be obtained from the third data table to crawl data according to the crawling rules to obtain the above-mentioned crawled web page data.
[0058] In combination with the first aspect, in some implementations of the first aspect, the method further includes:
[0059] When the current system time does not reach the crawling trigger time, the server calculates the waiting time according to the crawling trigger time and the current system time;
[0060] When the waiting time is greater than a first preset time period, the server executes a local lock for the first preset time period, and reacquires the crawled data source from the first queue after releasing the local lock;
[0061] When the waiting time is not greater than the first preset time length, the server executes a local lock for the waiting time, and re-acquires the crawled data source from the first queue after releasing the local lock.
[0062] Among them, because when the above-mentioned server obtains the crawl data source from the first queue, the current system time may not have reached the crawl trigger time, then it is necessary to wait until the system time reaches the crawl trigger time. However, considering that there may be new data crawling task applications during the waiting time, the server cannot execute new data crawling tasks if it is in a waiting state. Therefore, the server can set a first preset time. If the calculated waiting time is greater than the first preset time, the server executes the local lock for the first preset time to avoid wasting resources due to long-term locking. If the calculated waiting time is not greater than the first preset time, the server executes the local lock waiting time to execute the next round of crawling tasks as soon as possible.
[0063] In combination with the first aspect, in some implementations of the first aspect, the data crawling system further includes an electronic device, and the method further includes:
[0064] The electronic device sends a data request to the server, requesting to obtain the crawled webpage data;
[0065] The electronic device receives and displays the web page data from the server.
[0066] Among them, if the business application corresponding to the above-mentioned data crawling task is installed on the electronic device held by the user, the business application can display the data crawling results and can respond to the user's search request. Then, the electronic device can request the stored data crawling results (i.e. the above-mentioned web page data) from the server and display them to the user for viewing, or the electronic device receives the user's search request, searches for the corresponding content from the data crawling results and displays them. In this way, the server can send the crawled web page data to the electronic device in a timely manner to improve the user's usage perception.
[0067] In a second aspect, the present application provides a data crawling system, which includes a Web client and a server, and the data crawling system is used to execute any one of the methods in the technical solution of the first aspect above.
[0068] In a third aspect, the present application provides a device, which is included in a data crawling system, and has the function of implementing the above-mentioned first aspect and the possible implementation method of the above-mentioned first aspect. The function can be implemented by hardware, or by hardware executing corresponding software. The hardware or software includes one or more modules or units corresponding to the above-mentioned functions. For example, a receiving module or unit, a processing module or unit, etc.
[0069] In a fourth aspect, the present application provides a Web client, comprising: one or more processors, and a memory;
[0070] The memory is coupled to the one or more processors, and the memory is used to store computer program codes, wherein the computer program codes include computer instructions, and the one or more processors call the computer instructions to enable the Web client to execute the corresponding process in the technical solution of the first aspect.
[0071] In a fifth aspect, the present application provides a server, comprising: one or more processors, and a memory;
[0072] The memory is coupled to the one or more processors, and the memory is used to store computer program code, the computer program code includes computer instructions, and the one or more processors call the computer instructions to enable the server to execute the corresponding process in the technical solution of the first aspect.
[0073] In a sixth aspect, the present application provides a computer-readable storage medium, which includes instructions. When the instructions are executed on a data crawling system, the data crawling system executes any one of the methods in the technical solution of the first aspect.
[0074] In a seventh aspect, the present application provides a computer program product, which includes: a computer program code, and when the computer program code runs on a data crawling system, the data crawling system executes any one of the methods in the technical solution of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0075] Figure 1 This is a schematic diagram of the system architecture of a data crawling method provided in an embodiment of the present application;
[0076] Figure 2 This is a schematic diagram of a Web management page on a Web client provided in an embodiment of the present application;
[0077] Figure 3 This is a schematic diagram of a data crawling task management page on a Web client provided in an embodiment of the present application;
[0078] Figure 4 This is another example of a data crawling task management page on a Web client provided in an embodiment of the present application;
[0079] Figure 5 This is another schematic diagram of a data crawling task management page on a Web client provided in an embodiment of the present application;
[0080] Figure 6This is another schematic diagram of a data crawling task management page on a Web client provided in an embodiment of the present application;
[0081] Figure 7 This is a schematic diagram of a URL management page on a Web client provided in an embodiment of the present application;
[0082] Figure 8 This is another schematic diagram of a URL management page on a Web client provided in an embodiment of the present application;
[0083] Fig. 9 This is another schematic diagram of a URL management page on a Web client provided in an embodiment of the present application;
[0084] Fig.10 This is another schematic diagram of a URL management page on a Web client provided in an embodiment of the present application;
[0085] Fig.11 This is a flowchart of a data crawling method provided in an embodiment of the present application;
[0086] Fig.12 It is a flowchart of another data crawling method provided in an embodiment of the present application;
[0087] Fig.13 This is a schematic diagram of the structure of a Web client provided in an embodiment of the present application;
[0088] Fig.14 It is a structural diagram of an example of a server provided in an embodiment of the present application;
[0089] Fig.15 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0090] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application. In the description of the embodiments of the present application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, "multiple" means two or more than two.
[0091] In the following, the terms "first", "second", and "third" are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first", "second", and "third" may explicitly or implicitly include one or more of the features.
[0092] In the current environment where the amount of network information is growing explosively, it is difficult for users to obtain the information they need from the huge amount of network information. For this reason, the concept of search engine is proposed. Search engine is an entrance for users to access the World Wide Web, which can assist users in searching for the information they need. However, considering that users from different fields and backgrounds often have different search purposes and needs, the results returned by the search engine may also contain web page content that users do not care about. In order to solve this problem, web crawlers that capture web page data in a targeted manner have emerged. They can automatically download web page data, and then filter and capture the information required by users from the web page data according to certain search strategies. They have a wide range of applications.
[0093] In the process of data crawling, due to the complexity of web page data and uneven content, sometimes only a small part of the data needs to be crawled. For example, when crawling hot list content with high user attention, only the title, author, popularity value and other data of the hot list content need to be crawled, and other data does not need to be crawled. Therefore, R&D personnel need to write code to align the regular expressions used in data crawling, and they also need to change the code in the case of different user needs. Obviously, this way of writing code will consume a lot of manpower, and the release cycle after the code is written is also relatively long, resulting in low efficiency of data crawling.
[0094] In view of this, an embodiment of the present application provides a data crawling method, which allows R&D personnel to dynamically configure the data crawling process on a Web management page, reducing the labor cost of writing code, and the dynamic configuration process can improve the flexibility of data crawling. At the same time, the Web management page does not require a code publishing process, and a data crawling task can be created as long as the page can be accessed, thereby improving the efficiency of data crawling.
[0095] Next, we will first introduce the application scenarios of the data crawling method in this application. In some embodiments, the data crawling method can be applied to Figure 1 In the system architecture shown, the system architecture may include a Web client, a server, and an electronic device. The Web client and the server may communicate with each other, and the electronic device and the server may also communicate with each other.
[0096] Among them, the R&D personnel can log in and access the Web management page on the Web client. The Web management page provides a crawler management function, under which data crawling task management, uniform resource locator (URL) management and other functions are provided. The data crawling task management function can be used to create data crawling tasks, control the start and stop of data crawling tasks, and set the crawling time interval to perform data crawling regularly and continuously. The URL management function can be used to create a URL data source and configure the URL data source. The URL data source created here can be selected when creating a data crawling task to select which data source to crawl (it can also be understood as which URL address to crawl). After triggering the start of the data crawling task on the Web client, the Web client can send the task request to the server, and the server can execute the data crawling task in the background and store the data crawling results. In some implementations, the data crawling task can be executed continuously and the stored data crawling results can be continuously updated.
[0097] For the above-mentioned electronic device (for example, a mobile phone), if the electronic device is installed with a business application corresponding to the above-mentioned data crawling task, the business application can display the data crawling results and can respond to the user's search request. For example, the business application can be a smart search APP, then the electronic device can request the stored data crawling results from the server and display them to the user for viewing, or the electronic device receives the user's search request, searches for the corresponding content from the data crawling results and displays them. In some implementations, when the user performs a refresh operation through the business application, the electronic device can request the latest data crawling results from the server.
[0098] Therefore, in the above Figure 1 Based on the system architecture, R&D personnel can dynamically configure the data crawling process on the Web management page, which is more convenient and faster than the traditional way of writing code.
[0099] In other scenarios, the above system architecture can also be used for the timed acquisition of some interface data. For example, by configuring the interface address and the acquisition content, the corresponding interface data can be automatically acquired.
[0100] Next, we will introduce the process of configuring the data crawling process on the Web client. Take the Web client as a personal computer (PC) as an example. Figure 2As shown, the Web client can log in to access the Web management page, for example, the Web management page can be the smart search operation cloud page. On the smart search operation cloud page, a crawler management control 21 is presented on the left task bar. After clicking the crawler management control 21, sub-function controls will be displayed below the control, including but not limited to the data crawling task management control 22 and the URL management control 23. After clicking a control, the right part of the smart search operation cloud page can display the corresponding configuration page.
[0101] For example, when the developer clicks the data crawling task management control 22, the Web client displays the following Figure 3 The data crawling task management page shown in the figure provides functions including but not limited to query and new additions. For the query function, you can query the created data crawling tasks based on the name and / or code of the data crawling task. The name here can be the task name defined by the developer when creating the data crawling task (for example, the name is novel list), and the code can be the code defined by the developer when creating the data crawling task (for example, the code corresponding to the novel list is novel). Figure 3 As an example, after entering "Novel List" in the name input box 31 and clicking the query control 32, the data crawling tasks of the created novel list can be displayed on the current page. Figure 4 As shown in the figure, for example, click the new control 41, and the content that needs to be filled in when adding a new data crawling task can be displayed on the current page. After the R&D personnel fill in the name, code, description, crawling data source, crawling time interval and other content, click the save control 42 to successfully create the data crawling task. Among them, the crawling time interval here is a way of scheduled data crawling, that is, after the first data crawling is completed, the second data crawling can be performed after the set time interval, and so on, to perform persistent scheduled data crawling.
[0102] When adding a new data crawling task, fill in the crawling data source process, such as Figure 5 As shown, the location of the crawled data source can be displayed in the form of a selection control 51. When the selection control 51 is clicked, a list of URL data sources that have been created can be displayed on the current page, and then the developer can select the URL data source to be crawled from the list. Figure 5 The URL data sources selected to be crawled are Hot List A and Hot List B.
[0103] After successfully creating a data crawling task, the created data crawling task can be displayed on the data crawling task management page. For example, the created data crawling task is a crawling task for social hot lists. Figure 6As shown, the record of the data crawling task also corresponds to an operation control 61, which is used to trigger different operations such as starting, stopping and editing the task. If the developer clicks on the task start, it triggers the data crawling task to start executing, and the Web client sends a task request to the server so that the server executes the corresponding data crawling task. After the task starts, if the developer clicks on the stop button again, the Web client sends a stop request to the server to trigger the data crawling task to stop executing. If the developer clicks on the edit button, the above screen will be redisplayed. Figure 4 The page allows developers to change the name, code, description, crawling data source, crawling time interval, etc.
[0104] In some implementations, after successfully creating a data crawling task, the Web client may also generate a unique identifier corresponding to the data crawling task, and send the identifier, name, code, description, crawling data source, crawling time interval and other information corresponding to the data crawling task to the server for storage. Optionally, the Web client may also use the name of the data crawling task as its corresponding unique identifier. Optionally, the server may store the received information corresponding to the data crawling task in the first data table.
[0105] By the above Figure 5 As can be seen from the description, when adding a new data crawling task, you need to select a crawling data source (i.e., URL data source). Therefore, you need to configure the crawling data source in advance for subsequent selection. The process of configuring the crawling data source can be done through the above Figure 2 For example, when the developer clicks the URL management control 23, the web client displays the following information: Figure 7 The URL management page shown in the figure provides functions including but not limited to query and new additions. For the query function, you can query the created URL data source based on the name and / or URL address of the URL data source. The name here can be the URL name defined by the developer when creating the URL data source (for example, the name is Hot List A), and the URL address can be the corresponding address entered by the developer when creating the URL data source (for example, the URL address corresponding to Hot List A is https: / / rebang.aaa). Figure 7 As an example, after inputting "Hot List A" in the name input box 71 and clicking the query control 72, the URL data source information of the created Hot List A can be displayed on the current page. Figure 8As shown in the figure, for example, click on the new control 81, and the content that needs to be filled in when adding a new URL data source can be displayed on the current page. After the R&D personnel fill in the name, code, description, URL address, type, etc., click on the save control 82 to successfully create the URL data source.
[0106] In some implementations, after successfully creating the URL data source, the Web client may also generate a unique identifier corresponding to the URL data source, and send the identifier, name, code, description, URL address, type, and other information corresponding to the URL data source to the server for storage. Optionally, the Web client may also use the name of the URL data source as its corresponding unique identifier. Optionally, the server may store the received information corresponding to the URL data source in a second data table.
[0107] After successfully creating a URL data source, the created URL data source can be displayed on the URL management page. For example, the created URL data source is the data source for Hot List B. Fig. 9 As shown, the record of the URL data source also corresponds to an operation control 91, which is used to trigger different operations such as editing, deleting, data extraction and crawling data query. If the developer clicks on edit, the Web client will redisplay the above Figure 8 The page allows developers to change the name, code, description, URL, type, etc. If the developer clicks Delete, the Web client can be triggered to delete the URL data source. If you click Data Extraction, you can configure crawling rules for the URL data source. Because if the above data crawling task is to crawl the URL data source, it usually only needs to crawl part of the corresponding URL address, so it is necessary to configure crawling rules to crawl the required content.
[0108] The process of configuring crawling rules for URL data sources can be as follows: Fig.10 As shown, the R&D personnel Fig. 9 After clicking the data extraction in the operation control 91, the Web client can jump to display Fig.10 The page shown. On this page, the original source of the URL data source, the crawler protocol restrictions and the corresponding URL address are displayed, and the original message acquisition control 92 is also displayed. When the original message acquisition control 92 is clicked, the Web client can send a request to the server, requesting the server to query the original message of the URL data source corresponding to the URL address, and display the data of the original message in the message information display box 93; it can be understood that the message information displayed here is the entire content of the URL data source corresponding to the URL address. After configuring the crawling rules, the required content can be captured from the message information.
[0109] After obtaining the original message of the URL corresponding to the URL data source, the developer can enter a rule expression in the crawling rule input box 94. In some implementations, the rule expression can be a regular expression (regex), which includes a combination of common characters (for example, letters from a to z) and special characters (called "meta characters"). In other implementations, the rule expression can be XML Path Language (XPath), which is a language for determining the location of a part in an XML document. The developer can select one of the rule expressions as needed. For example, Fig.10 Taking the input regular expression as an example, after the regular expression is input, the crawl test control 95 can be clicked to test the original message crawled according to the input regular expression to test whether the input regular expression is accurate. The information captured after the crawl test can be displayed in the message information display box 96 after crawling, for example Fig.10 As shown, the crawled results include field names, field values, and whether or not it is required. The field name (e.g., title) can be automatically filled in by the Web client according to the rule expression, or it can be manually filled in by the R&D personnel. The field value is the title information of each piece of information in the crawled original message. The whether or not it is required option indicates whether the field value is required. If "yes" is selected, it indicates that the field value is required. If the field value is empty during the subsequent data crawling process, the corresponding data crawling result can be discarded. If there is no abnormality in the crawling test result, the R&D personnel can click the save control 97, and the Web client can send the crawling rules (including the rule expression and the setting result of the setting of the whether or not option) and the crawling test result to the server for saving. It can be understood that the content saved here has a corresponding relationship with the identifier of the above-mentioned URL data source, that is, the corresponding crawling rules can be found through the identifier of the URL data source for subsequent data crawling. Optionally, the server can store the crawling rules configured for the URL data source in a third data table, that is, the third data table stores the configured rule expression and the setting result of the whether or not option. It can also be understood that since the format and data of the original message of the URL data source corresponding to the website address may change, the above regular expression can be adjusted regularly to crawl accurate message information.
[0110] Through the above configuration process, the configuration of the URL data source and data crawling tasks can be completed. Then, if the developer clicks the above Figure 6 When the task of operating control 61 in the process starts, the Web client sends a task request to the server so that the server can execute the corresponding data crawling task.
[0111] Next, we will introduce the detailed process of the server performing data crawling tasks. Fig.11 As shown, the process may include:
[0112] S11, the server receives the data crawling task request sent by the Web client.
[0113] The task request may carry an identifier corresponding to the data crawling task, such as a task ID, a name of the data crawling task, or other identifiers.
[0114] S12, the server starts the data crawling service and opens the persistence thread.
[0115] Because the crawling time interval is set when creating the data crawling task, that is, data crawling needs to be performed continuously, then the server needs to start a persistent thread for subsequent continuous acquisition of the data source to be crawled from the queue to be crawled.
[0116] In some implementations, the server can use the @conponet and @postconstruct annotations to start the persistence thread, and use the while (true) judgment logic to make the persistence thread loop.
[0117] S13, the server locks the data crawling service, and if the lock is successful, executes S15.
[0118] Among them, since there may be multiple servers deployed in the actual scenario, different servers can be used to execute different service processes. Therefore, if you want the data crawling service in the current server to execute the current data crawling task and prevent other servers or other services from repeatedly executing the current data crawling task, you can lock the current data crawling service.
[0119] In some implementations, the server can add local locks and distributed locks to the data crawling service. The local lock is used to prevent other services from concurrently reading and writing the data corresponding to the data crawling task, resulting in data inconsistency. The distributed lock is used to prevent multiple services from repeatedly executing the current data crawling task. Optionally, the server can use the setnx command to obtain a distributed lock and set the lock expiration time to N, for example, N is 1 minute. The expiration time is set here to prevent deadlock, that is, if the current server has an exception but keeps holding the lock, other servers will not execute the corresponding data crawling service, resulting in the inability to execute the data crawling task. If the expiration time is set, the server can unlock after N time, allowing the data crawling task to continue.
[0120] S14, the server obtains information of the data source to be crawled according to the identifier corresponding to the data crawling task in the task request, and stores it in a queue to be crawled.
[0121] It should be noted that the process of S14 obtaining the data source information to be crawled can be performed simultaneously with the above-mentioned processes of S12-S13 starting the data crawling service, that is, the server can perform multiple preparatory tasks for the data crawling task at the same time.
[0122] In S14, because the task request received by the server carries the identifier corresponding to the data crawling task, and the Web client has sent the identifier, name, code, description, crawling data source, crawling time interval and other information corresponding to the data crawling task to the server for storage after successfully creating the data crawling task, then the server can find the corresponding crawling data source (i.e., as the data source to be crawled) according to the identifier corresponding to the data crawling task. And because the Web client has also sent the identifier, name, code, description, URL address, type and other information corresponding to the URL data source to the server for storage after successfully creating the URL data source, then the server can find the identifier, URL address and other information of the crawling data source corresponding to the data crawling task. Exemplarily, the server can find the corresponding crawling data source (i.e., URL data source) according to the identifier of the data crawling task from the above-mentioned first data table, and then find the corresponding URL address according to the identifier of the URL data source from the above-mentioned second data table, thereby corresponding the data crawling task, URL data source and URL address and other information. Therefore, the server can obtain the information of the data source to be crawled according to the identifier corresponding to the data crawling task in the task request, the information of the data source to be crawled includes but is not limited to the identifier of the data source, the URL address and the crawling trigger time, and store the information of the data source to be crawled in the queue to be crawled. Figure 6 The task of crawling the Chinese social hot list corresponds to the two data sources to be crawled, namely, the hot list A and the hot list B. The server can store the information corresponding to the two data sources, the hot list A and the hot list B, in the queue to be crawled.
[0123] The crawling trigger time here can be the time determined by the system time + crawling time interval. For example, when the server receives the task request, the system time is 10:00:00, and the crawling time interval is 2 minutes. Then the crawling trigger time of the corresponding data crawling task should be 10:02:00, and the server can crawl data according to the crawling trigger time.
[0124] In some implementations, the queue to be crawled can be a zset queue of redis, which is an ordered queue in the redis database. When the server stores the information of the data source to be crawled in the zset queue, it can use the identifier of the data source as the value and the crawling trigger time as the score, and store them in order according to the crawling trigger time. For example, the information of the data source to be crawled can be stored in the zset queue in the order of the crawling trigger time from early to late.
[0125] It can be understood that since the R&D personnel can trigger and start multiple different data crawling tasks at different times on the Web client, the Web client will send multiple task requests to the server respectively to request to start different data crawling tasks. Then, the information of the data sources to be crawled corresponding to different data crawling tasks will be stored in the queue to be crawled, and there can also be multiple data sources to be crawled corresponding to one data crawling task. For example, the Web client starts 3 data crawling tasks, the first data crawling task corresponds to 1 data source to be crawled (A), and the crawling trigger time is 10:00:00, the second data crawling task corresponds to 2 data sources to be crawled (B and C), and the crawling trigger time is 10:05:00, and the third data crawling task corresponds to 2 data sources to be crawled (D and E), and the crawling trigger time is 10:10:00, then the information of the data sources A, B, C, D, and E to be crawled will be stored in the queue to be crawled.
[0126] S15, the server obtains a preset number of data sources to be crawled from the queue to be crawled.
[0127] Because the persistent thread started by the server will continue to crawl data, more and more data sources to be crawled will be stored in the crawl queue. If all the data sources to be crawled are crawled at the same time, it will undoubtedly increase the processing capacity of the server and cause excessive load. Therefore, the server can obtain a preset number of data sources to be crawled from the crawl queue each time for crawling. For example, the preset number can be 20.
[0128] In some implementations, when the queue to be crawled is a zset queue, the server can obtain the first 20 data sources to be crawled in the zset queue each time, that is, the first 20 data sources to be crawled sorted from early to late according to the crawling trigger time.
[0129] S16, the server determines whether the current system time reaches the crawling trigger time of the first data source to be crawled, and if so, executes S17, and if not, executes S21.
[0130] Among them, the first data source to be crawled is any one of the above-mentioned preset number of data sources to be crawled.
[0131] From the above description, it can be seen that each data source to be crawled has a corresponding crawl trigger time. The server will start crawling the corresponding data source only when the corresponding crawl trigger time is reached. Therefore, the server will determine whether the current system time has reached the crawl trigger time of the first data source to be crawled.
[0132] In some implementations, the server can use the current system time to subtract the crawling trigger time of the first data source to be crawled to obtain the time difference. If the time difference is greater than or equal to 0, it means that the current system time has reached the crawling trigger time of the first data source to be crawled, and the server needs to start the data crawling process. If the time difference is less than 0, it means that the current system time has not yet reached the crawling trigger time of the first data source to be crawled, and the server can continue to wait.
[0133] It can be understood that because the server obtains a preset number of data sources to be crawled, it is necessary to determine whether the crawling trigger time of each data source to be crawled has been reached. For multiple data sources that have reached the crawling trigger time, step S17 can be executed, and for multiple data sources that have not reached the crawling trigger time, step S21 can be executed.
[0134] S17, the server calculates the first waiting time of the first data source to be crawled.
[0135] Among them, the first data source to be crawled at this time is the data source to be crawled that reaches the crawling trigger time. The first waiting time waittime can be obtained by using the crawling trigger time - the current system time. The calculated first waiting time is used for the subsequent control of the local lock time.
[0136] It can be understood that since the current system time has reached the crawling trigger time of the first data source to be crawled, the first waiting time waittime will be less than or equal to 0, and the absolute value of waittime can be used to control the local lock time later.
[0137] S18, the server stores the URL corresponding to the first data source to be crawled into the data crawling queue for the crawler engine to crawl the data.
[0138] That is, for each first data source to be crawled that reaches the crawling trigger time, the server can first store the URL addresses corresponding to these data sources into the data crawling queue, so that the crawler engine reads the URL addresses from the data crawling queue in sequence to crawl data.
[0139] For details about the data crawling process of the crawler engine, see the following Fig.12 The description of is not repeated here.
[0140] S19, the server deletes the information of the first data source to be crawled from the queue to be crawled, and determines the next crawling trigger time of the first data source to be crawled.
[0141] S20, the server stores the updated information of the first data source to be crawled into the queue to be crawled again, and then executes S22.
[0142] Because the server has stored the URL address corresponding to the first data source to be crawled into the data crawling queue, and the subsequent crawler engine will perform the data crawling task, the server can delete the information of the first data source to be crawled, and after determining the next crawling time, store the updated information of the first data source to be crawled into the crawling queue again for the next crawling process, thereby realizing a continuous automatic scheduled data crawling process. It can be understood that the updated information of the first data source to be crawled includes but is not limited to the identifier of the data source, the URL address, and the next crawling trigger time and other information.
[0143] In some implementations, the server determines the next crawling trigger time of the first data source to be crawled by: obtaining the crawling time interval of the data crawling task corresponding to the first data source to be crawled, and then using the current system time + the corresponding crawling time interval, which is the next crawling trigger time. Therefore, the above-mentioned continuous data crawling process can also be understood as a timed data crawling process, and the timed duration is the crawling time interval.
[0144] It can also be understood that for each first data source to be crawled, the server will execute the above steps S18-S20.
[0145] In some implementations, if a crawling time interval is not configured on the Web client for the above data crawling task, the server may also set a default crawling time interval, thereby timing and continuously performing the data crawling process at the set crawling time interval.
[0146] S21, the server calculates the second waiting time of the first data source to be crawled.
[0147] Among them, the first data source to be crawled at this time is the data source to be crawled that has not reached the crawling trigger time. The second waiting time waittime can be obtained by using the crawling trigger time - the current system time. The calculated second waiting time is used for the subsequent control of the local lock time.
[0148] S22, the server deletes the distributed lock.
[0149] The purpose of the server deleting the distributed lock here is to prevent the deadlock caused by the current service occupying the distributed lock. For example, when a data crawling task that has not reached the crawling trigger time is waiting to be executed, the corresponding service occupies the distributed lock. If a new data crawling task comes in, the new data crawling task may not be executed. Therefore, the server can delete the distributed lock first and re-lock it in the next round of data crawling.
[0150] S23, the server determines whether the first waiting time or the second waiting time is greater than the first preset time length, and if so, executes S24, and if not, executes S25.
[0151] S24, the server executes the local lock for the first preset time, then releases the lock and returns to S13.
[0152] S25, the server executes the local lock for the first waiting time or the second waiting time, and then releases the lock and returns to S13.
[0153] That is to say, while waiting for the next data crawling, the server will execute the local lock according to the first waiting time or the second waiting time. To avoid the next execution time being later than the crawling trigger time, it will be judged whether the waiting time is greater than the first preset time (for example, the first preset time is 1 minute). If it is greater than the first preset time, the local lock will be locked for the first preset time to avoid wasting resources due to long-term locking. If it is not greater than the first preset time, the local lock will be locked for the first waiting time or the second waiting time to execute the next round of crawling tasks as soon as possible. In this way, after executing the local lock and releasing the lock, the server will return to the above step S13 to automatically start the next round of crawling tasks.
[0154] Exemplarily, assuming that the crawling trigger time of data crawling task A is 10:35:00, and the current system time is 10:30:30, that is, the current system time has not reached the crawling trigger time, the second waiting time is calculated to be 4 minutes and 30 seconds. When the first preset time is 1 minute, the second waiting time is greater than 1 minute, and the server is locked locally for 1 minute. Then release the lock and return to execute S13, that is, restart the next data crawling process. Because data crawling task A has not been executed, the next data crawling process will also judge data crawling task A. After the above-mentioned local locking for 1 minute, the current system time should reach 10:31:30, which still has not reached the crawling trigger time. The second waiting time is calculated to be 3 minutes and 30 seconds, and the local locking is still required for 1 minute, and so on. Until the current system time reaches 10:34:30, the second waiting time is calculated to be 30 seconds. The second waiting time is less than 1 minute, then the server is locked locally for 30 seconds, and then the lock is released and returned to execute S13. Since the current system time has reached 10:35:00, reaching the crawling trigger time, the server can store the URL corresponding to the data crawling task A into the data crawling queue for the crawler engine to crawl data.
[0155] In some implementations, the above steps performed by the server may be performed by a scheduled task engine running in the server.
[0156] After the server stores the URL corresponding to the second data source to be crawled into the data crawling queue in S18, the crawler engine (running in the server) recognizes that there is data stored in the data crawling queue and can start crawling data. Fig.12 As shown, taking the server as the execution subject as an example, the data crawling process may include:
[0157] S31, the server starts the persistence thread.
[0158] It should be noted that the persistence thread opened here is not the same thread as the persistence thread in the above S12. The persistence thread of the above S12 is used to continuously obtain the data source to be crawled from the queue to be crawled, so as to store the URL address corresponding to the data source to be crawled that reaches the crawling trigger time into the data crawling queue, and the persistence thread of S31 is used to continuously crawl data according to the URL address.
[0159] S32, the server initializes the web page downloader and the download thread pool.
[0160] Among them, the web page downloader is a data downloader used to download the corresponding web page data according to the URL address. The server can initialize the web page downloader or use the default web page downloader according to the specific data crawling business. The download thread pool is used to download web page data concurrently, that is, it can concurrently download web page data corresponding to different URL addresses. The server can initialize the download thread pool or create a default download thread pool according to the specific data crawling business.
[0161] S33, the server determines whether the status of the download thread pool is running, if yes, executes S34, if not, ends the process.
[0162] That is, when the status of the download thread pool is normal (running), the server can execute the subsequent data crawling process. If the status of the download thread pool is not running (an exception may occur or the operation stops), the current process ends.
[0163] S34, the server obtains the URL corresponding to the first data source to be crawled from the data crawling queue.
[0164] S35, determine whether the obtained URL is empty, if it is empty, execute S36, if not empty, execute S37.
[0165] Because the above server has stored the URL address corresponding to the first data source to be crawled into the data crawling queue, the URL address corresponding to the first data source to be crawled can be obtained from the data crawling queue at this time. Taking into account some abnormal factors, such as read and write abnormalities, the URL address obtained by the server may be empty. Then, the server can determine whether the obtained URL address is empty. If it is not empty, the data crawling process can be carried out normally. If it is empty, the current round of data crawling cannot be executed, and the next round of process can be carried out. For example, the URL address obtained by the server is the URL of the above hot list A.
[0166] S36, the server executes the local lock for a second preset time period, then releases the lock and returns to S33.
[0167] When the URL obtained is empty, the server can execute a local lock for a second preset time length to avoid frequent next rounds of cycles and waste of resources. In some implementations, the second preset time length can be 1 second.
[0168] It can be understood that after the server releases the lock and returns to S33, when the URL address is obtained from the data crawling queue, the next new URL address is obtained.
[0169] S37, the server submits the download task through the download thread pool to download the web page data corresponding to the URL.
[0170] When the acquired URL is not empty, the server can trigger the download of the web page data corresponding to the URL. Here, the download task can be submitted through the download thread pool to download the web page data corresponding to the URL.
[0171] In some implementations, the maximum number of threads in the download thread pool may be 2C+1, and the minimum number of threads may be 2C+1, where C is the number of CPU cores in the server. The same maximum number of threads and minimum number of threads are set here to maximize the use of CPU resources. The maximum length of the download task queue in the download thread pool may be M (for example, M is 1000) to ensure that all download tasks are successfully submitted as much as possible. If a download task fails to be submitted, the server may also record the corresponding download task, for example, in a data table, and the download task in the data table may be reprocessed later.
[0172] In some implementations, the process of downloading the webpage data corresponding to the URL address may be performed by a webpage downloader, and the specific process may include:
[0173] A: Get the download link from the web downloader.
[0174] The download linker is a long connection associated with a webpage domain name, and the desired data can be downloaded through the download linker. For example, the download linker can be implemented using an http connection pool.
[0175] B: Set the http request message.
[0176] Among them, the http request message can carry information such as request header, request body, configured socket timeout (socketTimeout), configured connection timeout (connectTimeout), etc. The request header is used to describe the metadata of the http request message, including information such as request method and request protocol. The request body is used to pass the parameters or content required for the http request to the web server.
[0177] C: Request web page data from the web server according to the http request message.
[0178] D: Get the web page data stream and convert the data stream into a text string.
[0179] That is, after setting up the http request message, the web page downloader can request the corresponding web page data from the web page server. Generally, the web page data initially obtained is in the format of a web page data stream, and the data stream can also be converted into a text string (string).
[0180] S38, the server obtains the crawling rules corresponding to the first data source to be crawled.
[0181] Due to the above Fig.10 The crawling rules of the URL data source are configured in the server, and the first data source to be crawled is a data source in the configured URL data source, then the server can obtain the crawling rules corresponding to the first data source to be crawled. In some implementations, if the Web client sends the crawling rules and other information of the URL data source to the server, and the server stores the information in the third data table, then the server can obtain the crawling rules corresponding to the first data source to be crawled from the third data table.
[0182] S39, determine whether the crawling rule is empty, if it is empty, end the process, if not empty, execute S40.
[0183] Taking into account some scenarios where read and write exceptions or the crawling rules of the URL data source are not fully configured, if the crawling rules obtained by the server are empty, the process can be ended. If the crawling rules are not empty, the subsequent rule matching process can be executed.
[0184] S40, the server matches the web page data according to the crawling rules.
[0185] The server can crawl the data according to the regular expressions in the crawling rules (such as the above Fig.10 ) to match the acquired web page data.
[0186] S41, determine whether the crawling rules are matched, if not matched, end the process, if matched, execute S42.
[0187] That is, it is determined whether the crawling rule used in S40 matches the data, and if it matches, subsequent processing is performed on the crawled data.
[0188] S42, the server loops to obtain matching data, and obtains data corresponding to required options according to crawling rules.
[0189] Since the amount of web page data corresponding to a URL is relatively large, the server can obtain matching data in a loop to reduce the probability of missing data. In some implementations, after obtaining matching data, the server can also splice the matching data according to the order of the expressions in the above regular expression, for example, splicing the matching data in the order of title and source. Then, the server can also obtain the above Fig.10 The results of whether the items are required in the configured crawling rules are set, and the data corresponding to the required items in the matching data are obtained.
[0190] S43, determine whether the matching data is empty, if it is empty, end the process, if not empty, execute S44.
[0191] S44, determine whether the data corresponding to the required item is empty, if it is empty, end the process, if not empty, execute S45.
[0192] That is, the server will determine whether the matching data and the data corresponding to the required items are empty. If the data is empty, the record can be deleted and the current process ends. If the matching data and the data corresponding to the required items are not empty, the subsequent steps are executed.
[0193] S45, the server formats the matching data and saves it to a storage medium.
[0194] For example, in the scenario where the matching data is a text string, the server can convert it into JSON format to save it in a storage medium. In some implementations, the server can also fill in the matching data into a complete sentence and then save it. For example, for the data crawling of the above-mentioned social hot list, the title, source and other information can be filled in and spliced into a complete sentence.
[0195] In addition, in some implementations, after the server completes crawling the web page data corresponding to the current URL, it can also determine whether there is any child node information under the URL, that is, whether there is a sub-page. If so, it can also obtain the URL of the sub-page, continue crawling data for the sub-page, and save the crawled data in the storage medium.
[0196] In some implementations, the above process of S38-S45 analyzing the downloaded web page data can be performed by a web page parser in the server.
[0197] It can be understood that after completing this round of data crawling process, the server can return to S33 to continue to obtain the URL address from the data crawling queue for persistent data crawling process.
[0198] It can also be understood that according to the above Figure 1 As shown in the system architecture, after the server completes data crawling, if the electronic device used by the user has installed a business application corresponding to the above-mentioned data crawling task, the business application can display the data crawling results and respond to the user's search request.
[0199] The above data crawling method can first dynamically configure the data crawling task on the Web client to reduce the labor cost of writing code. At the same time, the server can continuously perform the data crawling process according to the crawling time interval, which improves the efficiency of data crawling and also improves the flexibility of the data crawling process.
[0200] In some scenarios, the above process of dynamically configuring the data crawling task can be performed on the server in addition to the Web client, that is, the R&D personnel directly open the Web management page on the server to configure. In other scenarios, if the Web client has a certain computing processing capability, the above data crawling process can also be performed on the Web client.
[0201] For the above-mentioned Web client, it can be a device such as a laptop, a PC, etc., for example, Fig.13 2 is a schematic diagram of a structure of a Web client provided in an embodiment of the present application. The Web client may include a processor 210, a memory 220, a communication module 230, and the like.
[0202] The processor 210 may include one or more processing units, and the memory 220 is used to store program codes and data. In the embodiment of the present application, the processor 210 may execute computer-executable instructions stored in the memory 220 .
[0203] The communication module 230 can be used for communication between various internal modules of the Web client, or for communication between the Web client and other devices. For example, if the Web client communicates with other devices via a wired connection, the communication module 230 may include an interface, such as a universal serial bus (USB) interface. The USB interface may be an interface that complies with USB standard specifications, specifically a Mini USB interface, a Micro USB interface, a USB Type C interface, etc. The USB interface may be used to connect a charger to charge the Web client, may be used to transmit data between the Web client and other devices, may be used to connect headphones, play audio through the headphones, etc.
[0204] Alternatively, the communication module 230 may include an audio device, a radio frequency circuit, a Bluetooth chip, a wireless fidelity (Wi-Fi) chip, a near-field communication (NFC) module, etc., and the interaction between the Web client and other devices can be achieved in a variety of different ways.
[0205] In addition, the Web client may further include a display screen 240, which may display images or videos in the human-computer interaction interface, etc. For example, the Web management page may be displayed for R&D personnel to configure data crawling tasks.
[0206] Optionally, the Web client may further include peripheral devices 250, such as a mouse, a keyboard, a speaker, a microphone, etc.
[0207] It should be understood that, in addition to Fig.13 In addition to the various components or modules listed in the figure, the embodiment of the present application does not specifically limit the structure of the Web client. In other embodiments of the present application, the Web client may also include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure can be implemented in hardware, software, or a combination of software and hardware.
[0208] The above server may be a single server or a server cluster. For example, Fig.14 : is a schematic diagram of the structure of an example server provided in an embodiment of the present application. The server includes a processor, a memory and a network interface connected via a system bus. Among them, the processor of the server is used to provide computing and control capabilities. The memory of the server includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the server can be used to store the configuration data of the above-mentioned data crawling tasks, the configuration data of the URL data source, etc. The network interface of the server can be used to communicate with external devices through a network connection.
[0209] The electronic device mentioned above may be a mobile phone, a tablet computer, etc. used by a user. For example, Fig.15 1 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Taking the electronic device as a mobile phone as an example, the electronic device may include a processor 110, an external memory interface 120, an internal memory 121, a USB interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identity module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0210] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0211] The controller can be the nerve center and command center of the electronic device. The controller can generate operation control signals according to the instruction operation code and timing signal to complete the control of fetching and executing instructions.
[0212] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0213] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to electronic devices. The mobile communication module 150 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves from the antenna 1, and filter, amplify, and process the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1. In some embodiments, at least some of the functional modules of the mobile communication module 150 may be set in the processor 110. In some embodiments, at least some of the functional modules of the mobile communication module 150 may be set in the same device as at least some of the modules of the processor 110.
[0214] The wireless communication module 160 can provide wireless communication solutions for electronic devices, including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, modulates the frequency of the electromagnetic wave signal and filters it, and sends the processed signal to the processor 110. The wireless communication module 160 can also receive the signal to be sent from the processor 110, modulate the frequency of it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.
[0215] The electronic device implements the display function through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.
[0216] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device may include 1 or N display screens 194, where N is a positive integer greater than 1.
[0217] The internal memory 121 can be used to store computer executable program codes, and the executable program codes include instructions. The processor 110 executes various functional applications and data processing of the electronic device by running the instructions stored in the internal memory 121. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area can store data created during the use of the electronic device (such as audio data, a phone book, etc.), etc. In addition, the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.
[0218] It is to be understood that the structure illustrated in the embodiments of the present application does not constitute a specific limitation on the electronic device. In other embodiments of the present application, the electronic device may include more or fewer components than shown in the figure, or combine certain components, or split certain components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0219] The above describes in detail an example of a data crawling method provided by an embodiment of the present application. It is understandable that, in order to implement the above functions, the Web client, server, and electronic device include hardware and / or software modules corresponding to the execution of each function. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application in combination with the embodiments, but such implementation should not be considered to exceed the scope of the present application.
[0220] The embodiment of the present application can divide the functional modules of the Web client, server and electronic device according to the above method example. For example, each function can be divided into various functional modules, such as a detection unit, a processing unit, a display unit, etc., or two or more functions can be integrated into one module. The above integrated module can be implemented in the form of hardware or in the form of a software functional module. It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation.
[0221] It should be noted that all relevant contents of each step involved in the above method embodiment can be referred to the functional description of the corresponding functional module and will not be repeated here.
[0222] In the case of an integrated unit, the electronic device may further include a processing module, a storage module and a communication module. The processing module may be used to control and manage the actions of the electronic device. The storage module may be used to support the electronic device to execute stored program codes and data, etc. The communication module may be used to support the electronic device to communicate with other devices.
[0223] Among them, the processing module can be a processor or a controller. It can implement or execute various exemplary logic boxes, modules and circuits described in conjunction with the disclosure of this application. The processor can also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a digital signal processor and a microprocessor, and the like. The storage module can be a memory. The communication module can specifically be a device that interacts with other electronic devices, such as a radio frequency circuit, a Bluetooth chip, a Wi-Fi chip, etc.
[0224] The embodiment of the present application also provides a computer-readable storage medium, in which a computer program is stored, and when the computer program is executed by a processor, the processor executes the data crawling method of any of the above embodiments. The storage medium may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
[0225] An embodiment of the present application also provides a computer program product. When the computer program product runs on a computer, it enables the computer to execute the above-mentioned related steps to implement the data crawling method in the above-mentioned embodiment.
[0226] In addition, an embodiment of the present application also provides a device, which can specifically be a chip, component or module, and the device may include a connected processor and memory; wherein the memory is used to store computer execution instructions, and when the device is running, the processor can execute the computer execution instructions stored in the memory so that the chip executes the data crawling method in the above-mentioned method embodiments.
[0227] Among them, the Web client, server, electronic device, computer-readable storage medium, computer program product or chip provided in this embodiment are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above, and will not be repeated here.
[0228] Through the description of the above implementation methods, technical personnel in the relevant field can understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0229] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0230] The above contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A data crawling method, characterized in that: The method is applied to a data crawling system, the data crawling system includes a Web client and a server, and the method includes: The Web client displays a second page, where the second page is used to configure the crawled data source; The Web client receives a second configuration operation on the crawled data source through the second page, and sends the configuration content of the crawled data source to the server for storage, wherein the second configuration operation at least includes configuration of a website address corresponding to the crawled data source; The Web client displays a first page, where the first page is used to configure a data crawling task; The Web client receives a first configuration operation for the data crawling task through the first page, and sends the configuration content of the data crawling task to the server for storage, wherein the first configuration operation at least includes configuration of a crawling data source and a crawling time interval of the data crawling task, and the configuration of the crawling data source of the data crawling task includes: selecting at least one crawling data source from the crawling data sources configured by the second configuration operation; When the Web client receives the operation of starting the data crawling task, it sends a task request to the server to request the server to execute the data crawling task, wherein the task request carries an identifier of the data crawling task; The server obtains a crawling data source corresponding to the data crawling task according to the identifier of the data crawling task, and stores the crawling data source and the crawling trigger time into a first queue, wherein the crawling trigger time is determined by the server according to the current system time and the crawling time interval; The server obtains the crawl data source from the first queue, and crawls web page data according to the URL corresponding to the crawl data source when the current system time reaches the crawl trigger time; Deleting the information of the crawled data source from the first queue, and determining the next crawling trigger time of the crawled data source according to the crawling time interval; Re-storing the crawling data source and the next crawling trigger time into the first queue to crawl the webpage data regularly; When the current system time does not reach the crawling trigger time, the server calculates the waiting time according to the crawling trigger time and the current system time; When the waiting time is greater than a first preset time period, the server executes a local lock for the first preset time period, and reacquires the crawled data source from the first queue after releasing the local lock; When the waiting time is not greater than the first preset time length, the server executes a local lock for the waiting time, and re-acquires the crawled data source from the first queue after releasing the local lock.
2. The method according to claim 1, characterized in that The first page includes a first control, and the Web client receives a first configuration operation for the data crawling task through the first page, including: The Web client displays a first input control for configuring the data crawling task in response to a user clicking the first control; The crawling data source and the crawling time interval input by the user on the first input control are received to complete the first configuration operation.
3. The method according to claim 2, characterized in that After completing the first configuration operation, the method further includes: The Web client displays the configuration content of the data crawling task and a second control on the first page, where the second control is used to trigger the start and stop of the data crawling task.
4. The method according to claim 3, characterized in that The Web client receives an operation to start the data crawling task, including: The Web client receives a click operation on the second control by the user, triggering the start of the data crawling task.
5. The method according to claim 1, characterized in that The second page includes a third control, and the Web client receives a second configuration operation on the crawled data source through the second page, including: The Web client displays a second input control for configuring the crawled data source in response to a user clicking the third control; Receive the URL corresponding to the crawled data source input by the user on the second input control, and complete the second configuration operation.
6. The method according to claim 5, characterized in that After completing the second configuration operation, the method further includes: The Web client displays the configuration content of the crawled data source and a fourth control on the second page, where the fourth control is used to trigger the configuration of the crawling rules of the crawled data source.
7. The method according to claim 6, characterized in that After the Web client displays the configuration content of the crawled data source and the fourth control on the second page, the method further includes: The Web client receives a click operation on the fourth control by the user, and displays a third page for configuring the crawling rule; receiving a click operation of the user on the fifth control on the third page, and acquiring and displaying original message information of the website address corresponding to the crawled data source; Receive a regular expression input by the user on a third input control on the third page, and perform a crawling test on the original message information according to the regular expression.
8. The method according to any one of claims 1 to 7, characterized in that The crawling of the webpage data according to the URL corresponding to the crawling data source includes: The server obtains the crawling rules corresponding to the crawling data source; The content in the website corresponding to the crawling data source is crawled according to the crawling rules to obtain the web page data.
9. The method according to claim 8, characterized in that The crawling rule includes mandatory settings for fields included in the crawling results. After obtaining the webpage data, the method further includes: If the mandatory setting corresponding to the first field in the webpage data is mandatory, and the value of the first field is empty, the server discards the webpage data.
10. The method according to any one of claims 1 to 7, characterized in that After crawling the webpage data according to the website corresponding to the crawling data source, the method further includes: The server saves the web page data in a storage medium.
11. The method according to any one of claims 1 to 7, characterized in that The data crawling system further includes an electronic device, and the method further includes: The electronic device sends a data request to the server, requesting to obtain the crawled webpage data; The electronic device receives and displays the web page data from the server.
12. A data crawling system, characterized in that: The data crawling system comprises a Web client and a server, and the data crawling system is used to execute the method as claimed in any one of claims 1 to 11.
13. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes instructions, which, when executed on a data crawling system, cause the data crawling system to perform the method of any one of claims 1 to 11.
Citation Information
Patent Citations
A data capture system method and apparatus
CN109213824A
Data crawling method and device, storage medium and electronic equipment
CN113934912A
