Content crawling method and device and distributed crawler system
By adopting a horizontal layered architecture and Redis queue to distribute data in the e-commerce crawler system, the problems of machine load imbalance and poor scalability are solved, and more efficient resource utilization and system scalability are achieved.
Patent Information
- Application Number
- CN201810549416.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2018-05-31
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2038-05-31
AI Technical Summary
When the existing e-commerce crawler system is deployed on multiple machines, it is easy to cause unbalanced machine loads, unable to fully utilize resources, poor program scalability, and complicated update and deployment.
Adopting a horizontal layered architecture design pattern, the crawling process is created according to the type of crawling results, and data is distributed through the Redis queue to achieve random polling and dynamic expansion of the crawling process.
It achieves machine load balancing, makes full use of resources, enhances the scalability and fault tolerance of the crawler system, and facilitates dynamic expansion of the system.
Smart Images

Figure CN110633429B
Abstract
Description
Background Art
[0002] With the development of e-commerce, more and more e-commerce websites have been born. When online shoppers buy goods, they all hope to buy better goods at a favorable price, so they will check the product prices, preferential activities, user reviews and other information on multiple e-commerce websites for comparison. Therefore, the relevant technology provides an e-commerce crawler system to timely summarize the product information of various e-commerce websites, which is convenient for online shoppers to query and compare.
[0003] In the related art, separate e-commerce crawler modules are often designed and written for different pages of each e-commerce website to crawl the information of the corresponding e-commerce website. Each e-commerce crawler module includes sub-modules for crawling all information (e-commerce product category information, product details, etc.). When working, an e-commerce crawler module will call these sub-modules to start multiple working threads on a machine to crawl different information respectively. This vertical mode design based on single-machine multi-threading makes each crawler module only crawl the information of one e-commerce, and each crawler module contains sub-modules with different functions. The program has poor scalability, is not convenient for dynamic expansion of the system, and the update and deployment process is complicated.
[0004] In addition, crawling and analyzing web pages is a task that consumes a lot of network resources and CPU resources. If the amount of data is huge, it is far from enough to rely on one machine alone, and crawlers need to be deployed on multiple machines. Because the crawling and analysis difficulty of each e-commerce website is different, and the resources consumed are also different, when deploying on multiple machines, it is easy to cause unbalanced machine loads and fail to fully utilize machine resources to crawl e-commerce product information.
[0005] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present disclosure, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention
[0006] The purpose of the present disclosure is to provide a content crawling method and a content crawling device, which are used to overcome one or more problems caused by limitations and defects of related technologies at least to a certain extent.
[0007] According to a first aspect of an embodiment of the present disclosure, a content crawling method is provided, comprising: creating multiple crawling processes according to addresses of multiple websites to be crawled; when a crawling result of the crawling process is a network address, writing the network address into one of multiple address queues corresponding to the address type according to the address type of the network address; creating a crawling process corresponding to the address type according to the address queue, and repeating the previous step until the crawling result is a preset content.
[0008] In an exemplary embodiment of the present disclosure, writing the network address into one of a plurality of address queues corresponding to the address type according to the address type of the network address comprises:
[0009] Determining an address type of the network address, and determining a plurality of address queues according to the address type;
[0010] randomly determining a write queue from among the multiple address queues;
[0011] Starting from the write queue, multiple network address crawling results of a crawling process are written into the multiple address queues in sequence and in a loop.
[0012] In an exemplary embodiment of the present disclosure, the step of creating a crawling process corresponding to the address type according to the address queue includes:
[0013] Determine the address type of the address queue, and determine the content of the crawling process according to the address type;
[0014] A plurality of crawling processes are created for each of the plurality of address queues.
[0015] In an exemplary embodiment of the present disclosure, the method further includes: storing the preset content in a database.
[0016] In an exemplary embodiment of the present disclosure, the address queue is stored in a Redis database.
[0017] According to a second aspect of an embodiment of the present disclosure, a content crawling device is provided, including:
[0018] An initial process creation module, configured to create multiple crawling processes according to the addresses of multiple websites to be crawled;
[0019] a classification queue creation module, configured to, when the crawling result of the crawling process is a network address, write the network address into one of a plurality of address queues corresponding to the address type according to the address type of the network address;
[0020] The classification process creation module is configured to create a crawling process corresponding to the address type according to the address queue, and repeat the previous step until the crawling result is a preset content.
[0021] In an exemplary embodiment of the present disclosure, the classification queue creation module includes:
[0022] An address queue determination unit, configured to determine an address type of the network address, and determine a plurality of address queues according to the address type;
[0023] a start queue determination unit, configured to randomly determine a write queue from the plurality of address queues;
[0024] The cyclic writing unit is configured to start from the writing queue and cyclically write multiple network address crawling results of a crawling process into the multiple address queues in sequence.
[0025] According to a third aspect of the present disclosure, a distributed crawler system is provided, comprising:
[0026] A storage device, configured to store crawling results or address queues, wherein the crawling results include network addresses and preset contents;
[0027] Multiple processors, each of which is configured to run one or more master control processes, and the master control process is configured to execute the content crawling method as described in any one of the above items.
[0028] According to a fourth aspect of the present disclosure, an electronic device is provided, comprising: a memory; and a processor coupled to the memory, wherein the processor is configured to execute any one of the methods described above based on instructions stored in the memory.
[0029] According to a fifth aspect of the present disclosure, a computer-readable storage medium is provided, on which a program is stored, and when the program is executed by a processor, the content crawling method as described in any one of the above items is implemented.
[0030] The content crawling method, device and distributed crawler system provided by the present disclosure construct a horizontal layered architecture design mode that is conducive to expansion by arranging the crawling process according to the type of crawling results rather than the design structure of each website, so that one crawler module can crawl data from different websites, and network requests and computing pressure will not be concentrated on a certain complex website, which is conducive to achieving machine load balancing and fully utilizing resources. In addition, by separating the crawler master control process and the storage module, a horizontally scalable distributed crawler system is constructed, which can enhance the scalability and fault tolerance of the crawler system, adapt to dynamic network changes, and facilitate dynamic expansion of the system.
[0031] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] The accompanying drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the specification are used to explain the principles of the present disclosure. Obviously, the accompanying drawings described below are only some embodiments of the present disclosure, and for ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without creative work.
[0033] Figure 1 The flowchart of the content crawling method in the exemplary embodiment of the present disclosure is schematically shown.
[0034] Figure 2 A sub-flow chart of a content crawling method in an exemplary embodiment of the present disclosure is schematically shown.
[0035] Figure 3 A schematic diagram of the data packet structure of the address queue in an exemplary embodiment of the present disclosure is schematically shown.
[0036] Figure 4 A sub-flow chart of a content crawling method in an exemplary embodiment of the present disclosure is schematically shown.
[0037] Figure 5A and Figure 5B A schematic diagram of a content crawling method for an application scenario in an exemplary embodiment of the present disclosure is schematically shown.
[0038] Figure 6 A schematic diagram of a distributed crawler system in an exemplary embodiment of the present disclosure is schematically shown.
[0039] Figure 7 A block diagram of a content crawling device in an exemplary embodiment of the present disclosure is schematically shown.
[0040] Figure 8 A block diagram schematically shows an electronic device in an exemplary embodiment of the present disclosure.
[0041] Fig. 9 The diagram schematically shows a computer-readable storage medium in an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION
[0042] Example embodiments will now be described more fully with reference to the accompanying drawings. However, example embodiments can be implemented in a variety of forms and should not be construed as being limited to the examples set forth herein; on the contrary, these embodiments are provided so that the present disclosure will be more comprehensive and complete, and the concepts of the example embodiments are fully conveyed to those skilled in the art. The described features, structures, or characteristics may be combined in one or more embodiments in any suitable manner. In the following description, many specific details are provided to provide a full understanding of the embodiments of the present disclosure. However, those skilled in the art will appreciate that the technical solutions of the present disclosure may be practiced while omitting one or more of the specific details, or other methods, components, devices, steps, etc. may be adopted. In other cases, known technical solutions are not shown or described in detail to avoid obscuring various aspects of the present disclosure.
[0043] In addition, the accompanying drawings are only schematic diagrams of the present disclosure, and the same reference numerals in the drawings represent the same or similar parts, so their repeated description will be omitted. Some of the block diagrams shown in the accompanying drawings are functional entities, which do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or implemented in one or more hardware modules or integrated circuits, or implemented in different networks and / or processor devices and / or microcontroller devices.
[0044] The exemplary embodiments of the present disclosure are described in detail below with reference to the accompanying drawings.
[0045] Figure 1 The flowchart of the content crawling method in the exemplary embodiment of the present disclosure is schematically shown. Figure 1 , the content crawling method 100 may include:
[0046] Step S1, creating multiple crawling processes according to the addresses of multiple websites to be crawled;
[0047] Step S2, when the crawling result of the crawling process is a network address, writing the network address into one of a plurality of address queues corresponding to the address type according to the address type of the network address;
[0048] Step S3, creating a crawling process corresponding to the address type according to the address queue, and repeating the previous step until the crawling result is the preset content.
[0049] The content crawling method, device and distributed crawler system provided by the present invention construct a horizontal layered architecture design pattern that is conducive to expansion by arranging the crawling process according to the type of crawling results rather than the design structure of each website, so that one crawler module can crawl data from different websites, and network requests and computing pressure will not be concentrated on a certain complex website, which is conducive to achieving machine load balancing and fully utilizing resources.
[0050] Next, each step of the content crawling method 100 is described in detail.
[0051] In step S1, multiple crawling processes are created according to the addresses of multiple websites to be crawled.
[0052] Different from the related art in which a crawler module is designed separately for each website to be crawled based on the structure of each website to be crawled, the crawler module of the embodiment of the present disclosure can crawl multiple websites.
[0053] The crawler module of the disclosed embodiment may include a master control process and crawler templates of different types of web pages. The master control process may create or destroy crawler processes (crawlers), and each crawler process is set by the master control process according to the crawler template.
[0054] Taking crawling product details from an e-commerce website as an example, for multiple e-commerce websites to be crawled, the main control process can first create multiple homepage crawling processes according to the URLs of each e-commerce website to crawl the page addresses of multiple product categories of the e-commerce website. Exemplarily, a homepage crawling process can be created for each website to be crawled.
[0055] In step S2, when the crawling result of the crawling process is a network address, the network address is written into one of a plurality of address queues corresponding to the address type according to the address type of the network address.
[0056] Figure 2 It is a sub-flow chart of an embodiment of the present disclosure.
[0057] refer to Figure 2 In an exemplary embodiment of the present disclosure, step S2 may include:
[0058] Step S21, determining the address type of the network address, and determining a plurality of address queues according to the address type;
[0059] Step S22, randomly determining a write queue from the multiple address queues;
[0060] Step S23, starting from the write queue, multiple network address crawling results of a crawling process are written into the multiple address queues in sequence and in a loop.
[0061] In step S21, following the example of step S1, it is first determined that the network address crawled by a homepage crawling process is a page address (URL, Uniform Resource Locator) of multiple commodity categories, and then the address queue corresponding to the commodity category page address is determined in multiple address queues. Among them, the uniform resource locator is a concise representation of the location and access method of resources available on the Internet, and is the address of a standard resource on the Internet. Each file on the Internet has a unique URL, which contains information indicating the location of the file and how the browser should handle it.
[0062] The URL data stored in the address queue can be in binary data protocol in TLV (Type-Length-Value) format. TLV is a variable-length binary encoding method, where Type specifies the type of a single packet or a combined packet, Length is the size of the current packet, and Value contains the actual content of the data packet.
[0063] Figure 3 It is a schematic diagram of the structure of a URL data packet in an embodiment of the present disclosure.
[0064] refer to Figure 3 Based on the principle of TLV data protocol, the data packet protocol of the disclosed embodiment is divided into two parts: header and body. The header part contains fields such as data packet length (len), command word (cmd), merchant number (app_id), etc. The cmd field determines the data type. For example, cmd equals 0x1, which means that the data packet stores the URL of the product list page, such as https: / / list.jd.com / list.html? cat=737,794,798; cmd equals 0x2, which means that the data packet stores the URL of the product detail page, such as https: / / item.jd.com / 5364377.html. The app_id field can be used to distinguish merchants. For example, app_id=1 can represent JD.com, and app_id=2 can represent Taobao. The body part is mainly used to store URLs, and can also be used to store other data. For example, when cmd=0x2, the category information of the product can be stored.
[0065] In an exemplary embodiment of the present disclosure, the address queue is stored in a Redis database.
[0066] Redis is an open source log-based Key-Value database that can be both memory-based and persistent. It supports multiple data types such as strings, hash tables (Maps), queues (Lists), sets (sets), and sorted sets (sorted sets).
[0067] In the embodiment of the present disclosure, Redis is used as a medium for the two-level crawler, and the URL crawling results of the previous level crawling process can be stored in the List data type, such as Figure 3 The binary data packet shown. After the previous crawling process crawls a URL and constructs a data packet, the "RPUSH key value" command can be used to write the data packet into the Redis queue. Different types of data packets (i.e. different cmds) are stored in different Redis queues.
[0068] Therefore, in step S21, the queue corresponding to the cmd may be first determined in multiple Redis queues according to the address type (cmd).
[0069] As the amount of data increases, the crawling and analysis tasks become arduous, requiring more processes to be started and more machines to be deployed to crawl data. In order to adapt to the dynamic expansion of the system and facilitate the deployment and update of the system, in some embodiments, the information of the Redis queue can be saved in the configuration center.
[0070] For example, the Redis instance list and the number of queue consumer processes of each instance can be stored in the configuration center, and the master control processes at all levels read them regularly for real-time updates. The configuration center is a distributed system that provides services for adding, deleting, checking and modifying configuration information. This disclosure only applies to this system and does not modify the operation mode of the system, so it is not specifically limited here.
[0071] One data packet type can set two pieces of configuration information, such as the Redis queue configuration and the number of consumer processes for each queue. If there are N types of data packets (with different cmds), the configuration center can have 2N pieces of configuration information. The Redis list configuration in the configuration center can be stored in Key-Value format, where the Key is "redis_list" and the Value is a list of Redis instances separated by "|". For example:
[0072] redis_list=192.168.132.144:6379|192.168.132.145:6379|192.168.132.144:6380.
[0073] In the embodiment of the present disclosure, a Redis instance represents a Redis queue.
[0074] In step S22, the crawling process can adopt a random polling method when writing the network address crawling result into the Redis queue. First, a write queue of a random position of the Redis list can be requested from the configuration center.
[0075] In step S23, starting from the write queue, the Redis list can be polled one by one, and the multiple network address crawling results crawled by the crawling process can be converted into data packets and written into each queue in turn.
[0076] For example, 10 address queues with cmd=0x01 are set, and the write queue for the random bit requested in step S22 is queue No. 6. The product list crawling process crawls 10 network addresses with cmd=0x01. Starting from address queue No. 6, the queue names for the data packets written by the crawling process are 6, 7, 8, 9, 0, 1, 2, 3, 4, and 5 respectively. If there are more network address crawling results, they can also be stored in each address queue in a cycle in the above order. In some cases, such as problems with network connectivity, it may cause a failure to write data packets to the current queue. At this time, the next queue can be written in sequence. It can be understood that the above numbers are only examples. In actual operation, the number of each type of address queue can be adjusted according to the settings of the content crawling task.
[0077] Since random polling is used to store data packets into each address queue, when there are multiple crawling processes executing crawling tasks for multiple websites, the number of data packets in each queue will not vary greatly due to the different data volumes of each website, thereby effectively ensuring the load balance of the storage device.
[0078] In step S3, a crawling process corresponding to the address type is created according to the address queue, and the previous step is repeated until the crawling result is the preset content.
[0079] Figure 4 is a sub-flow chart of an exemplary embodiment of the present disclosure.
[0080] refer to Figure 4 In an exemplary embodiment of the present disclosure, step S3 may include:
[0081] Step S31, determining the address type of the address queue, and determining the content of the crawling process according to the address type;
[0082] Step S32: creating multiple crawling processes for each of the multiple address queues.
[0083] To consume the address information in the address queue, the master process can create a certain number of consumer processes for each address queue based on the configuration information requested from the configuration center. Because the data volume and consumption task difficulty of addresses of different address types are different, different numbers of consumer processes can be configured for address queues of different address types. For example, the crawling process created for each address queue can use commands such as "LPOP key" to take out the data packets in the Redis queue and execute the crawling task until there are no data packets in the address queue, and the crawling process is destroyed.
[0084] A crawler template for each address type can be pre-set, so that the master process can create a crawler process according to the crawler template to perform crawling tasks for network addresses of different address types. Taking e-commerce crawling product details as an example, when the address type is a product list, the crawling rules for the product list can be set in advance and a template can be generated; when the address type is product details, the crawling rules for product details can be set in advance and a template can be generated.
[0085] In the disclosed embodiment, the final crawling target of the crawling task, i.e., preset content, such as product details, can be preset. Thus, when the crawling result is not the preset content but the next-level URL, the crawler and address queue can be used cyclically until the crawling result of the preset content is obtained.
[0086] In an exemplary embodiment of the present disclosure, the method further includes: storing the preset content in a database. Figure 3As can be seen from the setting of the data packet in the embodiment of the present disclosure, the crawling process can obtain the identification information of the target website, such as the e-commerce identifier, etc. Therefore, when the crawling result is the preset content, the preset content can be stored in the database according to the identification information of the target website, and the crawling process can be destroyed. The database can be, for example, MySQL, SQLSever, Oracle, DB2, etc., and the present disclosure is not limited thereto.
[0087] It should be noted that although the present embodiment uses the master control process to create a crawling process by determining the address type, in some other embodiments, a master control process can also be set for each address type, so that the master control process can create a crawling process corresponding to one address type only by reading the address queue information and process creation rules of the configuration center, so as to consume the address queue of one address type, and destroy the crawling process when there are no data packets or other preset conditions in the address queue.
[0088] Figure 5A and Figure 5B It is a schematic diagram of an application scenario of an embodiment of the present disclosure.
[0089] refer to Figure 5A and Figure 5B Taking crawling product details from multiple e-commerce websites as an example, you can set up a three-level crawler module, a Redis storage module, and a configuration center.
[0090] Each level of the three crawler modules is equipped with a master control process, which can create, monitor, rebuild or destroy multiple crawler processes by reading the Redis address queue recorded in the configuration center. The reading method can be, for example, periodic reading. By having the master control process regularly pull configuration information from the configuration center, developers can create and destroy processes by modifying the configuration information of the configuration center, which facilitates the dynamic expansion and contraction of crawler modules and storage modules at all levels.
[0091] In the example shown in Figure 5, the first-level crawler module is set to crawl the URL of the product list page, that is, crawl the URL of each category sub-page. Generally, its crawling task address is the homepage of the e-commerce website; the second-level crawler module is set to crawl the URL of the product details page; the third-level crawler module is set to crawl the product information of each product detail page, and store the crawled information in a distributed manner in the database. The main control process of each level of crawler module is connected through the Redis storage module. The upper level crawler module is the producer and the lower level crawler module is the consumer. The List data type of Redis is used as an intermediate storage queue to store the URL crawled by the crawling process of the upper level crawler module and provide it for consumption by the lower level crawler module.
[0092] The first-level crawler module is the origin of the crawling task. For each e-commerce company, the first-level master control process will create a first-level crawling process to crawl the URL of the product list page (subpages of each category) on the homepage of the e-commerce website. These first-level crawling processes encapsulate these URLs into binary data packets of cmd=0x1 according to the data protocol, and write them into the Redis address queue of cmd=0x1 in a random polling manner. The master control process of the second-level crawler module regularly reads the configuration information of the configuration center, and creates a crawling process to crawl the URL of the product detail page on the product list page according to the configuration information, so as to consume the data packet of cmd=0x1 in the Redis address queue of cmd=0x1, and encapsulate the crawling results into a data packet of cmd=0x2, and write them into the Redis address queue of cmd=0x2 in a random polling manner. The third-level crawler module consumes the data produced by the second-level crawler module, obtains the URL of the product detail page, crawls the product details on this page, and stores this information in the database corresponding to each e-commerce company.
[0093] The distributed e-commerce crawler system based on Redis provided in this embodiment adopts the architectural design of the horizontal model and the programming concept of producer-consumer to horizontally isolate the crawler modules and storage modules with different functions of the system, and uses the List type data (i.e., queue) of Redis as the intermediate queue for storing URLs to connect various modules together, thereby building a low-coupling and high-cohesion distributed system.
[0094] Figure 6 A distributed crawler system provided in one embodiment of the present disclosure includes:
[0095] A storage device 61, configured to store crawling results or address queues, wherein the crawling results include network addresses and preset contents;
[0096] A plurality of processors 62, each of which is configured to run one or more master control processes, wherein the master control processes are configured to execute any of the content crawling methods described above.
[0097] The content crawling structure shown in FIG5 can be deployed on multiple computers, so that each crawler module can crawl data from different e-commerce companies, so that the most onerous and resource-intensive tasks such as crawling and analyzing product detail pages are evenly distributed to each computer, making full use of machine resources and improving the performance of the crawling system. The disclosed embodiment relies on the configuration center to establish a dynamically scalable distributed e-commerce crawler system, which enhances the scalability of the system.
[0098] Corresponding to the above method embodiments, the present disclosure also provides a content crawling device, which can be used to execute the above method embodiments.
[0099] Figure 7 A block diagram of a content crawling device in an exemplary embodiment of the present disclosure is schematically shown.
[0100] refer to Figure 7 , the content crawling device 700 may include:
[0101] An initial process creation module 71, configured to create multiple crawling processes according to the addresses of multiple websites to be crawled;
[0102] The classification queue creation module 72 is configured to write the network address into one of a plurality of address queues corresponding to the address type according to the address type of the network address when the crawling result of the crawling process is a network address.
[0103] The classification process creation module 73 is configured to create a crawling process corresponding to the address type according to the address queue, and repeat the previous step until the crawling result is the preset content.
[0104] In an exemplary embodiment of the present disclosure, the classification queue creation module 72 includes:
[0105] An address queue determining unit 721 is configured to determine an address type of the network address and determine a plurality of address queues according to the address type;
[0106] A starting queue determining unit 722 is configured to randomly determine a write queue from the multiple address queues;
[0107] The cyclic writing unit 723 is configured to start from the write queue and cyclically write multiple network address crawling results of a crawling process into the multiple address queues in sequence.
[0108] Since the functions of the device 700 have been described in detail in the corresponding method embodiments, the present disclosure will not elaborate on them here.
[0109] It should be noted that, although several modules or units of the device for action execution are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more modules or units described above can be embodied in one module or unit. On the contrary, the features and functions of one module or unit described above can be further divided into multiple modules or units to be embodied.
[0110] In an exemplary embodiment of the present disclosure, an electronic device capable of implementing the above method is also provided.
[0111] It will be appreciated by those skilled in the art that various aspects of the present invention may be implemented as a system, method or program product. Therefore, various aspects of the present invention may be specifically implemented in the following forms, namely: a complete hardware implementation, a complete software implementation (including firmware, microcode, etc.), or a combination of hardware and software, which may be collectively referred to herein as a "circuit", "module" or "system".
[0112] Refer to the following Figure 8 An electronic device 800 according to this embodiment of the present invention will be described. Figure 8 The electronic device 800 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0113] like Figure 8 As shown, the electronic device 800 is in the form of a general computing device. The components of the electronic device 800 may include but are not limited to: at least one processing unit 810, at least one storage unit 820, and a bus 830 connecting different system components (including the storage unit 820 and the processing unit 810).
[0114] The storage unit stores program codes, which can be executed by the processing unit 810, so that the processing unit 810 performs the steps according to various exemplary embodiments of the present invention described in the above “Exemplary Method” section of this specification. For example, the processing unit 810 can perform the following steps: Figure 1 The step S1 shown in the figure is: creating multiple crawling processes according to the addresses of multiple websites to be crawled; step S2: when the crawling result of the crawling process is a network address, writing the network address into one of the multiple address queues corresponding to the address type according to the address type of the network address; step S3: creating a crawling process corresponding to the address type according to the address queue, and repeating the previous step until the crawling result is a preset content.
[0115] The storage unit 820 may include a readable medium in the form of a volatile storage unit, such as a random access memory unit (RAM) 8201 and / or a cache memory unit 8202 , and may further include a read-only memory unit (ROM) 8203 .
[0116] The storage unit 820 may also include a program / utility 8204 having a set (at least one) of program modules 8205, such program modules 8205 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0117] Bus 830 may represent one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
[0118] The electronic device 800 may also communicate with one or more external devices 900 (e.g., keyboards, pointing devices, Bluetooth devices, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 800, and / or communicate with any device that enables the electronic device 800 to communicate with one or more other computing devices (e.g., routers, modems, etc.). Such communication may be performed via an input / output (I / O) interface 850. Furthermore, the electronic device 800 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via a network adapter 860. As shown, the network adapter 860 communicates with other modules of the electronic device 800 via a bus 830. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 800, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, etc.
[0119] Through the description of the above implementation, it is easy for those skilled in the art to understand that the example implementation described here can be implemented by software, or by software combined with necessary hardware. Therefore, the technical solution according to the implementation of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the implementation of the present disclosure.
[0120] In an exemplary embodiment of the present disclosure, a computer-readable storage medium is also provided, on which a program product capable of implementing the above method of the present specification is stored. In some possible implementations, various aspects of the present invention can also be implemented in the form of a program product, which includes a program code, and when the program product is run on a terminal device, the program code is used to enable the terminal device to execute the steps according to various exemplary embodiments of the present invention described in the above "Exemplary Method" section of the present specification.
[0121] refer to Fig. 9As shown, a program product 1000 for implementing the above method according to an embodiment of the present invention is described, which can adopt a portable compact disk read-only memory (CD-ROM) and include program code, and can be run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited thereto. In this document, a readable storage medium can be any tangible medium containing or storing a program, which can be used by or in combination with an instruction execution system, an apparatus or a device.
[0122] The program product may use any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.
[0123] Computer readable signal media may include data signals propagated in baseband or as part of a carrier wave, in which readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Readable signal media may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0124] The program code embodied on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the foregoing.
[0125] Program code for performing the operations of the present invention may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving a remote computing device, the remote computing device may be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., through the Internet using an Internet service provider).
[0126] In addition, the above-mentioned figures are only schematic illustrations of the processes included in the method according to an exemplary embodiment of the present invention, and are not intended to be limiting. It is easy to understand that the processes shown in the above-mentioned figures do not indicate or limit the time sequence of these processes. In addition, it is also easy to understand that these processes can be performed synchronously or asynchronously, for example, in multiple modules.
[0127] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The specification and examples are to be considered exemplary only, and the true scope and concept of the present disclosure are indicated by the claims.
Claims
1. A content crawling method, characterized in that: include: Create multiple crawling processes according to the addresses of multiple websites to be crawled; When the crawling result of the crawling process is a network address, writing the network address into one of a plurality of address queues corresponding to the address type according to the address type of the network address; Creating a crawling process corresponding to the address type according to the address queue, and repeating the previous step until the crawling result is the preset content; Wherein, writing the network address into one of a plurality of address queues corresponding to the address type according to the address type of the network address comprises: Determining an address type of the network address, and determining a plurality of address queues according to the address type; randomly determining a write queue from among the multiple address queues; Starting from the write queue, multiple network address crawling results of a crawling process are written into the multiple address queues in sequence and in a loop.
2. The content crawling method according to claim 1, characterized in that: The step of creating a crawling process corresponding to the address type according to the address queue comprises: Determine the address type of the address queue, and determine the content of the crawling process according to the address type; A plurality of crawling processes are created for each of the plurality of address queues.
3. The content crawling method according to claim 1, characterized in that: Also includes: The preset content is stored in a database.
4. The content crawling method according to any one of claims 1 to 3, characterized in that: The address queue is stored in the Redis database.
5. A content crawling device, characterized in that: include: An initial process creation module, configured to create multiple crawling processes according to the addresses of multiple websites to be crawled; a classification queue creation module, configured to, when the crawling result of the crawling process is a network address, write the network address into one of a plurality of address queues corresponding to the address type according to the address type of the network address; a classification process creation module, configured to create a crawling process corresponding to the address type according to the address queue, and repeatedly run the classification queue creation module until the crawling result is a preset content; Wherein, the classification queue creation module includes: An address queue determination unit, configured to determine an address type of the network address, and determine a plurality of address queues according to the address type; a start queue determination unit, configured to randomly determine a write queue from the plurality of address queues; The cyclic writing unit is configured to start from the writing queue and cyclically write multiple network address crawling results of a crawling process into the multiple address queues in sequence.
6. A distributed crawler system, characterized in that: include: A storage device, configured to store crawling results or address queues, wherein the crawling results include network addresses and preset contents; Multiple processors, each of which is configured to run one or more master control processes, and the master control process is configured to execute the content crawling method as described in any one of claims 1-4.
7. An electronic device, characterized in that: include: Memory; as well as A processor coupled to the memory, the processor being configured to execute the content crawling method according to any one of claims 1 to 4 based on instructions stored in the memory.
8. A computer-readable storage medium having a program stored thereon, which, when executed by a processor, implements the content crawling method as described in any one of claims 1 to 4.
