WO2020015192A1 - 网页数据爬取方法、装置及存储介质 - Google Patents

网页数据爬取方法、装置及存储介质 Download PDF

Info

Publication number
WO2020015192A1
WO2020015192A1 PCT/CN2018/108218 CN2018108218W WO2020015192A1 WO 2020015192 A1 WO2020015192 A1 WO 2020015192A1 CN 2018108218 W CN2018108218 W CN 2018108218W WO 2020015192 A1 WO2020015192 A1 WO 2020015192A1
Authority
WO
WIPO (PCT)
Prior art keywords
url
webpage data
url list
list
storage path
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Ceased
Application number
PCT/CN2018/108218
Other languages
English (en)
French (fr)
Inventor
吴壮伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Technology Shenzhen Co Ltd
Original Assignee
Ping An Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Technology Shenzhen Co Ltd filed Critical Ping An Technology Shenzhen Co Ltd
Publication of WO2020015192A1 publication Critical patent/WO2020015192A1/zh
Anticipated expiration legal-status Critical
Ceased legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/951Indexing; Web crawling techniques
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/955Retrieval from the web using information identifiers, e.g. uniform resource locators [URL]
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Definitions

  • the present application relates to the field of data processing, and in particular, to a method for crawling webpage data, an electronic device, and a computer-readable storage medium.
  • the present application provides a webpage data crawling method, a server, and a computer-readable storage medium, the main purpose of which is to improve webpage data crawling efficiency.
  • the present application provides a method for crawling webpage data, which method includes:
  • S1 Receive a webpage data crawl request, and obtain a first URL (Uniform Resource Location, Uniform Resource Locator) list according to the webpage data crawl request.
  • the first URL list includes a URL to be crawled, and the first URL is crawled.
  • the list is stored in the first preset storage path where the preset configuration file is located;
  • the present application also provides an electronic device, which is characterized in that the device includes a memory and a processor, and the memory stores a webpage data crawling program that can be run on the processor, and the webpage data crawling program When the fetching program is executed by the processor, any step in the method for crawling webpage data as described above may be implemented.
  • the present application also provides a computer-readable storage medium, where the computer-readable storage medium includes a webpage data crawling program, and when the webpage data crawling program is executed by a processor, the above implementation can be implemented Any step in the webpage data crawling method.
  • the webpage data crawling method, electronic device, and computer-readable storage medium proposed in this application establish a docker application container based on the docker image to perform data processing in parallel.
  • the docker application container can save the waste of resources caused by starting the operating system, Level of consumption to provide similar isolation capabilities to virtual machines. Based on this framework, users only need to set up configuration files and generate related files as image files.
  • By building multiple docker application containers to crawl webpage data in parallel they can efficiently Complete the crawling of webpage data; ensure the integrity of the crawled webpage data by performing data verification on the crawled webpage data; and perform sub-URL deep mining of the crawled webpage data to ensure the comprehensiveness of the webpage data .
  • FIG. 1 is a flowchart of a preferred embodiment of a method for crawling webpage data of this application
  • FIG. 2 is a schematic diagram of a preferred embodiment of an electronic device of the present application.
  • FIG. 3 is a schematic diagram of a program module of a webpage data crawling program in FIG. 2 of the present application.
  • This application provides a method for crawling webpage data.
  • a flowchart of a preferred embodiment of a method for crawling webpage data of this application is shown. The method may be performed by a device, which may be implemented by software and / or hardware.
  • the docker-based webpage data crawling method includes steps S1-S5:
  • the first URL list includes URLs to be crawled, and store the first URL list to a preset configuration file. In the first preset storage path;
  • the electronic device serves as a server to establish a communication connection with a user terminal, receives a service data processing request sent by the user terminal, and processes the service data according to the request.
  • the electronic device may have a multi-core CPU (Central Processing Unit).
  • a docker image is configured on the electronic device. Specifically, a docker image is created based on the dockerfile rule.
  • the docker image includes a list dividing program, a parallel processing program, a data verification program, a data merging program, and the like, and the created docker image is saved to a second preset storage path.
  • After creating the docker image create multiple application containers based on the docker image. Each program can run independently in an application container, and multiple applications containers run independently of each other.
  • step S1 the method further includes steps:
  • a configuration file is generated according to the number of acquired parallel processes and the file path of each program, and the configuration file is stored in a first preset storage path.
  • the number of the above processes is adjusted according to the size of the multi-core CPU of the server and the situation of the CPU required for data processing.
  • the first URL list included in the webpage crawl request is the original URL list to be crawled.
  • each URL is determined based on the information of each URL in the first URL list to be crawled.
  • the index value corresponding to each URL update the index value information corresponding to each URL to the first URL list, and then store the updated first URL list into a first preset storage path, where the first preset Let the storage path be the Redis database.
  • the "index value corresponding to each URL in the first URL list" is obtained through the following steps:
  • a corresponding index value is matched for each URL in the first URL list.
  • the above characteristic information can be used to characterize the type of the web page, and the index value is used to retrieve the crawler program.
  • the mapping relationship between the feature information and the index value is obtained through the following steps:
  • Obtain a collection of specified URLs determine the characteristic information of each URL in the collection, and label index values for each URL; divide the specified URL in the collection into sub-collections corresponding to different index values according to the index values; and count each sub-collection separately
  • the proportion of different feature information, the feature information with the largest proportion is selected as the target feature information of the specified URL in each sub-set; the feature information and the index value corresponding to the sub-collection are used to determine the feature information and Mapping of index values.
  • the method further includes the following steps:
  • a prompt message is generated based on the URL, and a matching instruction for matching the URL index value is received.
  • the matching instruction includes the index value information corresponding to the URL that cannot match the index value according to the feature information.
  • Export the URL that cannot match the index value feed back the exported URL to the specified terminal, and artificially determine the corresponding index value for the exported URL.
  • the application container includes: a first application container, a plurality of second application containers, and a third application container.
  • the first application container is run to obtain a first URL list from a first preset storage path, and the above-mentioned list dividing program is called from a second preset storage path to divide the first URL list into N evenly.
  • URL sublists that is, N second URL lists, where N is an integer greater than 1.
  • Each second URL list includes multiple URLs and index value information corresponding to each URL, and each second URL list is stored in a preset storage path of the second URL list, that is, the third preset URL. Set the storage path.
  • the number N of the second URL list is the same as the number of the second application container. For example, when the number of the second application container is 5, N is 5, indicating that the first URL list is divided into 5 second URLs. List. Based on this step, the division and transfer of the list to be crawled and the corresponding program index value are realized.
  • the first application container invokes the configuration file from the second preset storage path, and allocates the CPU resources of the server to the plurality of second application containers described below, for the plurality of second application containers to perform webpage data crawling operations in parallel.
  • Data processing parameters are obtained from the configuration file, where the data processing parameters include the number of parallel processes N and the storage path of the crawled webpage data.
  • Running the third application container reading the webpage data crawled by the N second application containers from the fourth preset storage path, and sending the webpage data to the user terminal corresponding to the webpage crawling request, and Generate a prompt message.
  • the crawled webpage data needs to be verified.
  • the method further includes steps:
  • step S5 is continued.
  • a fourth application container is generated based on the docker image, and the fourth application container verifies the crawled webpage data.
  • the list is empty, that is, there are no unprocessed URLs, that is, there is no web data to be crawled; when P> Q, the number of URLs in the third URL list is PQ, and PQ URLs are pending URL, that is, web page data to be crawled.
  • For the third URL list containing URLs to be processed run the fourth application container to perform a web page data crawl operation, and crawl the web page data obtained in this step and the pass step.
  • the webpage data crawled by S4 is merged. It should be noted that, after a preset number of times (for example, 3 times) are performed on the URLs in the third URL list, a certain URL still exists in the third URL list, and early warning information is generated. Through this step, the omission of webpage data can be prevented and the integrity of the webpage data can be guaranteed.
  • the crawled web page data includes sub URLs.
  • a first URL list may be further mined to determine the sub URLs included in the web page data.
  • Corresponding web page data Specifically, before step S5, the method further includes steps:
  • Web page data corresponding to each second URL list is obtained from a fourth preset storage path, web page data corresponding to each second URL list is mined, a fourth URL list corresponding to each second URL list is determined, and the first Four URL lists are saved to the fifth preset storage path;
  • Perform a webpage data crawl operation on the fourth URL list continue to perform a sub-URL mining operation on the webpage data corresponding to the fourth URL list, extract a new sub-URL, and perform a webpage data crawl operation in a loop.
  • Each second URL list corresponds to a fourth URL list
  • the second application container that performs a webpage data crawl operation on the fourth URL list is the same as the second application container of the second URL list corresponding to the fourth URL list.
  • a depth threshold is set in advance (representing the number of times of deep mining sub URLs). When the number of times of deep mining URL list exceeds a preset depth threshold, stop mining new Sub URL operation.
  • the webpage data crawling method when a webpage data crawling request is received, obtains a first URL list to be processed according to the request, and stores it to a first preset storage path where a preset configuration file is located.
  • the pre-built docker image is read from the second preset storage path, and multiple application containers are generated according to the docker image.
  • the configuration file and the first URL list are read from the first preset storage path.
  • Application containers and configuration files divide the first URL list into multiple second URL lists, process multiple second URL lists in a multi-container parallel processing manner, and system resources will be allocated by the server to multiple application containers processing in parallel, Crawl the webpage data corresponding to each second URL list and send it to the user terminal corresponding to the webpage data request.
  • the solution of this application builds a docker application container based on the docker image to perform data processing in parallel.
  • the docker application container can save the waste of resources brought by starting the operating system, and provides process-level consumption similar to the isolation capability of a virtual machine.
  • users only need to set up configuration files and generate related files as mirror files.
  • By building multiple docker application containers to crawl webpage data in parallel they can efficiently complete webpage data crawling work.
  • crawling the webpage data Perform data verification to ensure the integrity of the crawled web page data; through sub-URL deep mining of the crawled web page data, ensure the comprehensiveness of the web page data.
  • FIG. 2 is a schematic diagram of a preferred embodiment of the electronic device 1 of the present application.
  • the electronic device 1 may be a terminal device having a data processing function, such as a smart phone, a tablet computer, a portable computer, a desktop computer, or the like.
  • the electronic device 1 includes a memory 11, a processor 12, and a network interface 13.
  • the memory 11 includes at least one type of readable storage medium, and the readable storage medium includes a flash memory, a hard disk, a multimedia card, a card-type memory (for example, SD or DX memory, etc.), a magnetic memory, a magnetic disk, an optical disk, and the like.
  • the memory 11 may be an internal storage unit of the electronic device 1 in some embodiments, such as a hard disk of the electronic device 1.
  • the memory 11 may also be an external storage device of the electronic device 1 in other embodiments, such as a plug-in hard disk, a smart memory card (SMC), and a secure digital (Secure Digital , SD) card, flash memory card (Flash card), etc. Further, the memory 11 may include both an internal storage unit and an external storage device of the electronic device 1.
  • the memory 11 can be used not only to store application software installed in the electronic device 1 and various types of data, such as a web page data crawler 10, etc., but also to temporarily store data that has been or will be output.
  • the processor 12 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip in some embodiments, and is configured to run program codes or processes stored in the memory 11 Data, such as webpage data crawler 10 and the like.
  • CPU central processing unit
  • controller a controller
  • microcontroller a microprocessor
  • microprocessor or other data processing chip in some embodiments, and is configured to run program codes or processes stored in the memory 11 Data, such as webpage data crawler 10 and the like.
  • the network interface 13 may optionally include a standard wired interface, a wireless interface (such as a WI-FI interface), and is generally used to establish a communication connection between the electronic device 1 and other electronic devices.
  • a wireless interface such as a WI-FI interface
  • FIG. 2 only shows the electronic device 1 with components 11-13. Those skilled in the art can understand that the structure shown in FIG. 2 does not constitute a limitation on the electronic device 1, and may include fewer or more There are many parts, or some parts are combined, or different parts are arranged.
  • the electronic device 1 may further include a user interface.
  • the user interface may include a display, an input unit such as a keyboard, and the optional user interface may further include a standard wired interface and a wireless interface.
  • the display may be an LED display, a liquid crystal display, a touch-type liquid crystal display, an organic light-emitting diode (OLED) touch device, or the like.
  • the display may also be referred to as a display screen or a display unit, for displaying information processed in the electronic device 1 and for displaying a visualized user interface.
  • a web page data crawling program 10 is stored in the memory 11 as a computer storage medium.
  • the processor 12 executes the web page data crawling program 10 stored in the memory 11, it is implemented The following steps:
  • A1. Receive a webpage data crawl request, and obtain a first URL (Uniform Resource Location, Uniform Resource Locator) list according to the webpage data crawl request.
  • the first URL list includes a URL to be crawled, and the first URL is crawled.
  • the list is stored in the first preset storage path where the preset configuration file is located;
  • the electronic device serves as a server to establish a communication connection with a user terminal, receives a service data processing request sent by the user terminal, and processes the service data according to the request.
  • the electronic device may have a multi-core CPU (Central Processing Unit).
  • a docker image is configured on the electronic device. Specifically, a docker image is created based on a dockerfile rule, and the docker image includes a list dividing program, a parallel processing program, a data verification program, a data merging program, and the like, and the created docker image is saved to a second preset storage path. After creating the docker image, create multiple application containers based on the docker image. Each program can run independently in an application container, and multiple applications containers run independently of each other.
  • step A1 the method further includes steps:
  • a configuration file is generated according to the number of acquired parallel processes and the file path of each program, and the configuration file is stored in a first preset storage path.
  • the number of the above processes is adjusted according to the size of the multi-core CPU of the server and the situation of the CPU required for data processing.
  • the first URL list included in the webpage crawl request is the original URL list to be crawled.
  • each URL is determined based on the information of each URL in the first URL list to be crawled.
  • the index value corresponding to each URL update the index value information corresponding to each URL to the first URL list, and then store the updated first URL list into a first preset storage path, where the first preset Let the storage path be the Redis database.
  • the "index value corresponding to each URL in the first URL list" is obtained through the following steps:
  • a corresponding index value is matched for each URL in the first URL list.
  • the above characteristic information can be used to characterize the type of the webpage, and the index value is used to retrieve the crawler program.
  • the mapping relationship between the feature information and the index value is obtained through the following steps:
  • Obtain a collection of specified URLs determine the characteristic information of each URL in the collection, and label index values for each URL; divide the specified URL in the collection into sub-collections corresponding to different index values according to the index values; and count each sub-collection separately
  • the proportion of different feature information, the feature information with the largest proportion is selected as the target feature information of the specified URL in each sub-set; the feature information and the index value corresponding to the sub-collection are used to determine the feature information and Mapping of index values.
  • the method further includes the following steps:
  • a prompt message is generated based on the URL, and a matching instruction for matching the URL index value is received.
  • the matching instruction includes the index value information corresponding to the URL that cannot match the index value according to the feature information.
  • Export the URL that cannot match the index value feed back the exported URL to the specified terminal, and artificially determine the corresponding index value for the exported URL.
  • A2 Read a pre-built docker image from the second preset storage path, and generate multiple application containers according to the docker image, where the application container includes a first application container, a second application container, and a third application container. ;
  • the application container includes: a first application container, a plurality of second application containers, and a third application container.
  • A3. Read a first URL list and a configuration file from the first preset storage path, divide the first URL list into multiple second URL lists based on the first application container, and divide the multiple The second URL list is stored in a third preset storage path;
  • the first application container is run to obtain a first URL list from a first preset storage path, and the above-mentioned list dividing program is called from a second preset storage path to divide the first URL list into N evenly.
  • URL sublists that is, N second URL lists, where N is an integer greater than 1.
  • Each second URL list includes multiple URLs and index value information corresponding to each URL, and each second URL list is stored in a preset storage path of the second URL list, that is, the third preset URL. Set the storage path.
  • the number of the second URL list is the same as the number of the second application container. For example, when the number of the second application container is 5, N is 5, which indicates that the first URL list is divided into 5 second URL lists. . Based on this step, the division and transfer of the list to be crawled and the corresponding program index value are realized.
  • the first application container invokes the configuration file from the second preset storage path, and allocates the CPU resources of the server to the plurality of second application containers described below for the plurality of second application containers to perform webpage data crawling operations in parallel.
  • Data processing parameters are obtained from the configuration file, where the data processing parameters include the number of parallel processes N and the storage path of the crawled webpage data.
  • Running the third application container reading the webpage data crawled by the N second application containers from the fourth preset storage path, and sending the webpage data to the user terminal corresponding to the webpage crawling request, and Generate a prompt message.
  • the crawled webpage data needs to be verified. Specifically, when the webpage data crawling program 10 is executed by the processor, before step A5, the following steps are further implemented:
  • a fourth application container is generated based on the docker image, and the fourth application container verifies the crawled webpage data.
  • the list is empty, that is, there are no unprocessed URLs, that is, there is no web data to be crawled; when P> Q, the number of URLs in the third URL list is PQ, and PQ URLs are pending URL, that is, web page data to be crawled.
  • For the third URL list containing URLs to be processed run the fourth application container to perform a web page data crawl operation, and crawl the web page data obtained in this step and the pass step.
  • the webpage data crawled by A4 is merged. It should be noted that, after a preset number of times (for example, 3 times) are performed on the URLs in the third URL list, a certain URL still exists in the third URL list, and early warning information is generated. Through this step, the omission of webpage data can be prevented and the integrity of the webpage data can be guaranteed.
  • the crawled web page data includes sub URLs.
  • a first URL list may be further mined to determine the sub URLs included in the web page data.
  • Corresponding web page data Specifically, when the webpage data scraping program 10 is executed by the processor, before step A5, the following steps are further implemented:
  • Web page data corresponding to each second URL list is obtained from a fourth preset storage path, web page data corresponding to each second URL list is mined, a fourth URL list corresponding to each second URL list is determined, and the first Four URL lists are saved to the fifth preset storage path;
  • Perform a webpage data crawl operation on the fourth URL list continue to perform a sub-URL mining operation on the webpage data corresponding to the fourth URL list, extract a new sub-URL, and perform a webpage data crawl operation in a loop.
  • Each second URL list corresponds to a fourth URL list
  • the second application container that performs a webpage data crawl operation on the fourth URL list is the same as the second application container of the second URL list corresponding to the fourth URL list.
  • a depth threshold is set in advance (representing the number of times of deep mining sub URLs). When the number of times of deep mining URL list exceeds a preset depth threshold, stop mining new Sub URL operation.
  • the electronic device 1 proposed in the above embodiment establishes a docker application container based on the docker image to perform data processing in parallel.
  • the docker application container can save the waste of resources caused by starting the operating system, and provides a process-level consumption similar to a virtual machine. Isolation ability. Based on this framework, users only need to set up configuration files and generate related files as mirror files.
  • the webpage data crawling work can be efficiently completed.
  • the obtained web page data is subjected to data verification to ensure the integrity of the crawled web page data; the sub-URL deep mining of the crawled web page data ensures the comprehensiveness of the web page data.
  • the webpage data crawling program 10 may be further divided into one or more modules, and the one or more modules are stored in the memory 11 and are provided by one or more processors (this The embodiment is executed by the processor 12) to complete the present application.
  • the module referred to in the present application refers to a series of computer program instruction segments capable of performing specific functions.
  • FIG. 3 it is a schematic block diagram of the webpage data crawling program 10 in FIG. 2.
  • the webpage data crawling program 10 may be divided into a receiving module 110, a container generating module 120, and a list dividing module 130.
  • Data scraping module 140 and data sending module 150 The functions or operation steps implemented by the modules 110-150 are similar to the above, which will not be described in detail here. For example, for example:
  • the receiving module 110 is configured to receive a webpage data crawling request, and obtain a first URL list according to the webpage data crawling request, where the first URL list includes URLs to be crawled, and store the first URL list to a preset In the first preset storage path where the configuration file is located;
  • the container generation module 120 is configured to read a pre-built docker image from a second preset storage path, and generate multiple application containers according to the docker image.
  • the application container includes a first application container and a second application container. A third application container; and
  • the list dividing module 130 is configured to read a first URL list and a configuration file from the first preset storage path, and divide the first URL list into a plurality of second URL lists based on the first application container. Storing the plurality of second URL lists into a third preset storage path;
  • a data crawling module 140 is configured to crawl webpage data corresponding to each URL in the multiple second URL lists based on the multiple second application containers, and save the webpage data to a fourth preset storage path Medium;
  • a data sending module 150 is configured to extract the webpage data from a fourth preset storage path based on the third application container, and send the webpage data to a user terminal corresponding to the webpage data crawl request.
  • an embodiment of the present application further provides a computer-readable storage medium.
  • the computer-readable storage medium includes a webpage data crawling program 10, and the webpage data crawling program 10 implements the following operations when executed by a processor:
  • A1. Receive a webpage data crawling request, and obtain a first URL list according to the webpage data crawling request.
  • the first URL list includes URLs to be crawled, and store the first URL list to a preset configuration file. In the first preset storage path;
  • A2 Read a pre-built docker image from the second preset storage path, and generate multiple application containers according to the docker image, where the application container includes a first application container, a second application container, and a third application container. ;
  • A3. Read a first URL list and a configuration file from the first preset storage path, divide the first URL list into multiple second URL lists based on the first application container, and divide the multiple The second URL list is stored in a third preset storage path;
  • the methods in the above embodiments can be implemented by means of software plus a necessary universal hardware platform, and of course, also by hardware, but in many cases the former is better.
  • Implementation Based on such an understanding, the technical solution of this application that is essentially or contributes to the existing technology can be embodied in the form of a software product.
  • the computer software product is stored in a storage medium such as ROM / RAM as described above. , Magnetic disk, optical disc), including a number of instructions to enable a terminal device (which may be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in the embodiments of this application.

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Transfer Between Computers (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本申请提供一种网页数据爬取方法,该方法根据接收的网页数据爬取请求读取第一URL列表,根据预先构建的docker镜像生成多个应用容器,将读取的所述第一URL列表划分为多个第二URL列表,并分别爬取所述多个第二URL列表中每条URL对应的网页数据,之后,该方法提取所述网页数据,并将所述网页数据发送至所述网页数据爬取请求对应的用户终端。本申请还提供一种电子装置及计算机存储介质。利用本申请,可以提高网页数据爬取效率。

Description

网页数据爬取方法、装置及存储介质
本申请基于巴黎公约申明享有2018年7月18日递交的申请号为CN201810791126.3、名称为“网页数据爬取方法、装置及存储介质”的中国专利申请的优先权,该中国专利申请的整体内容以参考的方式结合在本申请中。
技术领域
本申请涉及数据处理领域,尤其涉及一种网页数据爬取方法、电子装置及计算机可读存储介质。
背景技术
现有技术中,在一台服务器上运行多个任务的传统方式是启动多个虚拟机,然后在不同的虚拟机上运行不同的任务。传统的虚拟化技术多是采用基于VMware虚拟机,而VMware虚拟机的运行必须要运行整个操作系统,需要占用大量的系统资源。
然而,对于服务器来说,其CPU、内存、网络资源和磁盘资源等资源都是有限的。以网页数据爬取为例,目前爬虫的分布式受限于机器数量、CPU数量、线程个数和进程数量等,当服务器上启动的虚拟机过于消耗资源时,导致无法最大化利用系统资源,进而影响网页数据的爬取效率。
发明内容
鉴于以上内容,本申请提供一种网页数据爬取方法、服务器及计算机可读存储介质,其主要目的在于提高网页数据爬取效率。
为实现上述目的,本申请提供一种网页数据爬取方法,该方法包括:
S1、接收网页数据爬取请求,根据该网页数据爬取请求获取第一URL(Uniform Resource Location,统一资源定位符)列表,该第一URL列表中包括待爬取的URL,将该第一URL列表存储至预设的配置文件所在的第一预设存储路径中;
S2、从第二预设存储路径中读取预先构建的docker镜像,并根据所述docker镜像生成多个应用容器,其中,应用容器包括:第一应用容器、第二 应用容器、第三应用容器;
S3、从所述第一预设存储路径中读取第一URL列表及配置文件,基于所述第一应用容器将所述第一URL列表划分为多个第二URL列表,将所述多个第二URL列表存储至第三预设存储路径中;
S4、基于所述多个第二应用容器分别爬取所述多个第二URL列表中每条URL对应的网页数据,并将该网页数据保存至第四预设存储路径中;及
S5、基于所述第三应用容器从第四预设存储路径中提取所述网页数据,并将所述网页数据发送至所述网页数据爬取请求对应的用户终端。
此外,本申请还提供一种电子装置,其特征在于,该装置包括:存储器、处理器,所述存储器上存储有可在所述处理器上运行的网页数据爬取程序,所述网页数据爬取程序被所述处理器执行时,可实现如上所述网页数据爬取方法中的任意步骤。
此外,为实现上述目的,本申请还提供一种计算机可读存储介质,所述计算机可读存储介质中包括网页数据爬取程序,所述网页数据爬取程序被处理器执行时,可实现如上所述网页数据爬取方法中的任意步骤。
本申请提出的网页数据爬取方法、电子装置及计算机可读存储介质,基于docker镜像建立docker应用容器来并行的进行数据处理,docker应用容器可以节省启动操作系统所带来的资源浪费,以进程级别的消耗来提供与虚拟机类似的隔离能力,基于这个框架,用户只需要设置好配置文件、将相关程序生成镜像文件,通过建立多个docker应用容器并行地爬取网页数据,即可高效地完成网页数据爬取工作;通过对爬取到的网页数据进行数据验证,保证爬取到的网页数据的完整性;通过对爬取到的网页数据进行子URL深度挖掘,保证网页数据的全面性。
附图说明
图1为本申请网页数据爬取方法较佳实施例的流程图;
图2为本申请电子装置较佳实施例的示意图;
图3为本申请图2中网页数据爬取程序的程序模块示意图。
本申请目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。
具体实施方式
应当理解,此处所描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。
本申请提供一种网页数据爬取方法。参照图1所示,为本申请网页数据爬取方法较佳实施例的流程图。该方法可以由一个装置执行,该装置可以由软件和/或硬件实现。
在本实施例中,基于docker的网页数据爬取方法包括步骤S1-S5:
S1、接收网页数据爬取请求,根据该网页数据爬取请求获取第一URL列表,该第一URL列表中包括待爬取的URL,将该第一URL列表存储至预设的配置文件所在的第一预设存储路径中;
以下内容以电子装置作为执行主体对本申请方法实施例进行说明,其中,电子装置作为服务器与用户终端建立通讯连接,并接收用户终端发送的业务数据处理请求,根据请求对业务数据进行处理。该电子装置可以具有多核CPU(Central Processing Unit,中央处理器)。
可以理解的是,在接收用户终端发送的网页数据爬取请求并对网页数据进行爬取之前,在电子装置上配置好docker镜像。具体地,基于dockerfile规则创建docker镜像,该docker镜像中包含有列表划分程序、并行处理程序、数据验证程序、数据合并程序等,将创建的docker镜像保存至保存至第二预设存储路径中。在创建完docker镜像之后,基于该docker镜像创建多个应用容器。每一个程序可以独立地运行在应用容器中,多个应用容器之间的运行相互独立。
此外,在步骤S1之前,该方法还包括步骤:
接收客户端发送的配置参数,从配置参数中获取预先配置好并行进程的数量、网页数据及各程序的指定存储路径;
根据获取的并行进程的数量、各个程序的文件路径生成配置文件,将所述配置文件存储至第一预设存储路径中。
其中,上述进程的数量根据服务器的多核CPU的大小、以及数据处理需要占用的CPU情况来进行调整。
上述网页数据爬取请求中包含的第一URL列表为待爬取的原始URL列 表,在接收到网页数据爬取请求时,根据待爬取的第一URL列表中每条URL的信息,确定每条URL对应的索引值,将每条URL对应的索引值信息更新至上述第一URL列表中,然后将上述更新后的第一URL列表存储至第一预设存储路径中,其中,第一预设存储路径可以为Redis数据库。
作为一种实施方式,所述“第一URL列表中每条URL对应的索引值”通过以下步骤获取:
获取并分析第一URL列表中每条URL的具体信息,确定每条URL的特征信息;及
根据特征信息与索引值的映射关系,为第一URL列表中每条URL匹配对应的索引值。
其中,上述特征信息可以用于表征网页的类型,索引值用于调取爬虫程序。上述特征信息与索引值的映射关系通过以下步骤获取:
获取指定URL的集合,确定集合中每条URL的特征信息,为每条URL标注索引值;根据索引值将集合中的指定URL划分至不同索引值对应的子集合中;分别统计每个子集合中不同特征信息的占比,选择占比最大的特征信息作为各子集合中指定URL的目标特征信息;根据各子集合中指定URL的目标特征信息与该子集合对应的索引值,确定特征信息与索引值的映射关系。
进一步地,该方法还包括以下步骤:
当存在无法根据特征信息匹配索引值的URL时,基于该URL生成提示信息,并接收对该URL匹配索引值的匹配指令。
其中,上述匹配指令中包含上述无法根据特征信息匹配索引值的URL对应的索引值信息。将无法匹配索引值的URL导出,将导出的URL反馈至指定终端,人为地为导出的URL确定对应的索引值。
S2、从第二预设存储路径中读取预先构建的docker镜像,并根据所述docker镜像生成多个应用容器,其中,应用容器包括:第一应用容器、第二应用容器、第三应用容器;
在本实施例中,应用容器包括:一个第一应用容器、多个第二应用容器、一个第三应用容器。
S3、从所述第一预设存储路径中读取第一URL列表及配置文件,基于所述第一应用容器将所述第一URL列表划分为多个第二URL列表,将所述多 个第二URL列表存储至第三预设存储路径中;
具体地,运行所述第一应用容器,从第一预设存储路径中获取第一URL列表,从第二预设存储路径中调用上述列表划分程序,将第一URL列表平均地划分为N个URL子列表,即,N个第二URL列表,N为大于1的整数。其中,每一个第二URL列表中包含多条URL及每条URL对应的索引值信息,并将每一个第二URL列表存储至预设的第二URL列表的存储路径中,即,第三预设存储路径中。
在该步骤中,第二URL列表的数量N与第二应用容器的数量一致,例如,第二应用容器的数量为5时,N为5,表示将第一URL列表划分为5各第二URL列表。基于该步骤,实现待爬取列表及对应的程序索引值的划分及转移。
进一步地,第一应用容器从第二预设存储路径调用配置文件,将服务器的CPU资源分配给下述多个第二应用容器,供多个第二应用容器并行地执行网页数据爬取操作。从该配置文件中获取数据处理参数,其中,数据处理参数包括并行进程的数量N以及爬取到的网页数据的存储路径。
S4、基于所述多个第二应用容器分别爬取所述多个第二URL列表中每条URL对应的网页数据,并将该网页数据保存至第四预设存储路径中;
同步地运行所述N个第二应用容器,一个第二应用容器对应于的一个第二URL列表,所述多个第二应用容器分别从所述第三预设存储路径获取一个第二URL列表,根据每一个第二URL列表中每条URL对应的索引值,依次调用与索引值对应的爬虫程序,进行网页数据爬取操作,并将爬取到的网页数据保存至指定的存储路径中。其中,不同的第二应用容器对应同一个第四预设存储路径,即,不同第二应用内容器爬取到的网页数据保存至同一个文件夹中。通过该步骤,实现了网页数据的爬取及汇总过程。
S5、基于所述第三应用容器从第四预设存储路径中提取所述网页数据,并将所述网页数据发送至所述网页数据爬取请求对应的用户终端。
运行所述第三应用容器,从第四预设存储路径中读取上述N个第二应用容器爬取到的网页数据,并将网页数据发送至上述网页数据爬取请求对应的用户终端,并生成提示信息。
在其他实施例中,为了保证爬取到的网页数据的完整性,需对爬取到的网页数据进行验证。具体地,在步骤S5之前,该方法还包括步骤:
对所述网页数据的数量及第一URL列表中URL的数量进行比对,确定第三URL列表;
当第三URL列表不为空时,针对第三URL列表中的每条URL执行网页数据爬取操作,直至第三URL列表为空为止,并将所述第三URL列表对应的网页数据保存至第四预设存储路径中;
当第三URL列表为空时,继续执行步骤S5。
具体地,基于docker镜像生成第四应用容器,该第四应用容器对爬取到的网页数据进行验证。其中,第三URL列表中包含待爬取的URL及待爬取URL对应的索引值。可以理解的是,一条URL对应一条网页数据,假设统计得到第一URL列表中URL的数量为P、第四预设存储路径中网页数据的数量为Q,当P=Q时,说明第三URL列表为空,即不存在未处理的URL,也就是说,不存在待爬取的网页数据;当P>Q时,所述第三URL列表中URL的数量为P-Q,P-Q条URL为待处理的URL,即存在待爬取的网页数据,对于包含待处理URL的第三URL列表,运行上述第四应用容器,执行网页数据爬取操作,并将该步骤爬取到的网页数据与通过步骤S4爬取到的网页数据进行合并。需要说明是,当对第三URL列表中的URL执行预设次数(例如,3次)后,某URL仍然存在在第三URL列表中时,生成预警信息。通过该步骤,可以防止网页数据的遗漏,保证网页数据的完整性。
优选地,存在一种情况,爬取到的网页数据中包含子URL,为了保证爬取到的网页数据的全面性,还可以对第一URL列表进行深度挖掘,确定网页数据中包含的子URL对应的网页数据。具体地,在步骤S5之前,该方法还包括步骤:
分别从第三预设存储路径中获取第二URL列表及URL正则挖掘程序;
从第四预设存储路径中获取各第二URL列表对应的网页数据,对各第二URL列表对应的网页数据进行挖掘,确定每个第二URL列表对应的第四URL列表,将所述第四URL列表保存至第五预设存储路径中;
对所述第四URL列表执行网页数据爬取操作,继续对第四URL列表对应的网页数据进行子URL挖掘操作,抽取新的子URL,并进行网页数据爬取操作,以此循环。
每个第二URL列表对应一个第四URL列表,对第四URL列表执行网页 数据爬取操作的第二应用容器与该第四URL列表对应的第二URL列表的第二应用容器为同一个。
需要理解的是,为了防止一直深度挖掘新的子URL的情况,预先设置一个深度阈值(表示深度挖掘子URL的次数),当深度挖掘URL列表的次数超过预设的深度阈值时,停止挖掘新的子URL的操作。
上述实施例提出的网页数据爬取方法,在接收到网页数据爬取请求时,根据该请求获取待处理的第一URL列表,将其存储至预设的配置文件所在的第一预设存储路径中,从第二预设存储路径中读取预先构建的docker镜像,并根据该docker镜像生成多个应用容器,从上述第一预设存储路径中读取配置文件和第一URL列表,根据多个应用容器和配置文件将第一URL列表分割成多个第二URL列表,按照多容器并行处理的方式处理多个第二URL列表,系统资源会被服务器分配给并行处理的多个应用容器,爬取到各第二URL列表对应的网页数据,并将其发送至网页数据请求对应的用户终端。本申请的方案基于docker镜像建立docker应用容器来并行的进行数据处理,docker应用容器可以节省启动操作系统所带来的资源浪费,以进程级别的消耗来提供与虚拟机类似的隔离能力,基于这个框架,用户只需要设置好配置文件、将相关程序生成镜像文件,通过建立多个docker应用容器并行地爬取网页数据,即可高效地完成网页数据爬取工作;通过对爬取到的网页数据进行数据验证,保证爬取到的网页数据的完整性;通过对爬取到的网页数据进行子URL深度挖掘,保证网页数据的全面性。
本申请还提供一种电子装置。参照图2所示,为本申请电子装置1较佳实施例的示意图。
在本实施例中,电子装置1可以是智能手机、平板电脑、便携计算机、桌上型计算机等具有数据处理功能的终端设备。
该电子装置1包括存储器11、处理器12,及网络接口13。
其中,存储器11至少包括一种类型的可读存储介质,所述可读存储介质包括闪存、硬盘、多媒体卡、卡型存储器(例如,SD或DX存储器等)、磁性存储器、磁盘、光盘等。存储器11在一些实施例中可以是所述电子装置1的内部存储单元,例如该电子装置1的硬盘。存储器11在另一些实施例中也 可以是所述电子装置1的外部存储设备,例如该电子装置1上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)等。进一步地,存储器11还可以既包括该电子装置1的内部存储单元也包括外部存储设备。
存储器11不仅可以用于存储安装于该电子装置1的应用软件及各类数据,例如网页数据爬取程序10等,还可以用于暂时地存储已经输出或者将要输出的数据。
处理器12在一些实施例中可以是一中央处理器(Central Processing Unit,CPU)、控制器、微控制器、微处理器或其他数据处理芯片,用于运行存储器11中存储的程序代码或处理数据,例如网页数据爬取程序10等。
网络接口13可选的可以包括标准的有线接口、无线接口(如WI-FI接口),通常用于在该电子装置1与其他电子设备之间建立通信连接。
图2仅示出了具有组件11-13的电子装置1,本领域技术人员可以理解的是,图2示出的结构并不构成对电子装置1的限定,可以包括比图示更少或者更多的部件,或者组合某些部件,或者不同的部件布置。
可选地,该电子装置1还可以包括用户接口,用户接口可以包括显示器(Display)、输入单元比如键盘(Keyboard),可选的用户接口还可以包括标准的有线接口、无线接口。
可选地,在一些实施例中,显示器可以是LED显示器、液晶显示器、触控式液晶显示器以及有机发光二极管(Organic Light-Emitting Diode,OLED)触摸器等。其中,显示器也可以称为显示屏或显示单元,用于显示在电子装置1中处理的信息以及用于显示可视化的用户界面。
在图2所示的电子装置1实施例中,作为一种计算机存储介质的存储器11中存储有网页数据爬取程序10,处理器12执行存储器11中存储的网页数据爬取程序10时,实现如下步骤:
A1、接收网页数据爬取请求,根据该网页数据爬取请求获取第一URL(Uniform Resource Location,统一资源定位符)列表,该第一URL列表中包括待爬取的URL,将该第一URL列表存储至预设的配置文件所在的第一预设存储路径中;
以下内容以电子装置作为执行主体对本申请方法实施例进行说明,其中,电子装置作为服务器与用户终端建立通讯连接,并接收用户终端发送的业务数据处理请求,根据请求对业务数据进行处理。该电子装置可以具有多核CPU(Central Processing Unit,中央处理器)。
可以理解的是,在接收用户终端发送的网页数据爬取请求并对网页数据进行爬取之前,在电子装置上配置好docker镜像。具体地,基于dockerfile规则创建docker镜像,该docker镜像中包含有列表划分程序、并行处理程序、数据验证程序、数据合并程序等,将创建的docker镜像保存至保存至第二预设存储路径中。在创建完docker镜像之后,基于该docker镜像创建多个应用容器。每一个程序可以独立地运行在应用容器中,多个应用容器之间的运行相互独立。
此外,在步骤A1之前,该方法还包括步骤:
接收客户端发送的配置参数,从配置参数中获取预先配置好并行进程的数量、网页数据及各程序的指定存储路径;
根据获取的并行进程的数量、各个程序的文件路径生成配置文件,将所述配置文件存储至第一预设存储路径中。
其中,上述进程的数量根据服务器的多核CPU的大小、以及数据处理需要占用的CPU情况来进行调整。
上述网页数据爬取请求中包含的第一URL列表为待爬取的原始URL列表,在接收到网页数据爬取请求时,根据待爬取的第一URL列表中每条URL的信息,确定每条URL对应的索引值,将每条URL对应的索引值信息更新至上述第一URL列表中,然后将上述更新后的第一URL列表存储至第一预设存储路径中,其中,第一预设存储路径可以为Redis数据库。
作为一种实施方式,所述“第一URL列表中每条URL对应的索引值”通过以下步骤获取:
获取并分析第一URL列表中每条URL的具体信息,确定每条URL的特征信息;及
根据特征信息与索引值的映射关系,为第一URL列表中每条URL匹配对应的索引值。
其中,上述特征信息可以用于表征网页的类型,索引值用于调取爬虫程 序。上述特征信息与索引值的映射关系通过以下步骤获取:
获取指定URL的集合,确定集合中每条URL的特征信息,为每条URL标注索引值;根据索引值将集合中的指定URL划分至不同索引值对应的子集合中;分别统计每个子集合中不同特征信息的占比,选择占比最大的特征信息作为各子集合中指定URL的目标特征信息;根据各子集合中指定URL的目标特征信息与该子集合对应的索引值,确定特征信息与索引值的映射关系。
进一步地,该方法还包括以下步骤:
当存在无法根据特征信息匹配索引值的URL时,基于该URL生成提示信息,并接收对该URL匹配索引值的匹配指令。
其中,上述匹配指令中包含上述无法根据特征信息匹配索引值的URL对应的索引值信息。将无法匹配索引值的URL导出,将导出的URL反馈至指定终端,人为地为导出的URL确定对应的索引值。
A2、从第二预设存储路径中读取预先构建的docker镜像,并根据所述docker镜像生成多个应用容器,其中,应用容器包括:第一应用容器、第二应用容器、第三应用容器;
在本实施例中,应用容器包括:一个第一应用容器、多个第二应用容器、一个第三应用容器。
A3、从所述第一预设存储路径中读取第一URL列表及配置文件,基于所述第一应用容器将所述第一URL列表划分为多个第二URL列表,将所述多个第二URL列表存储至第三预设存储路径中;
具体地,运行所述第一应用容器,从第一预设存储路径中获取第一URL列表,从第二预设存储路径中调用上述列表划分程序,将第一URL列表平均地划分为N个URL子列表,即,N个第二URL列表,N为大于1的整数。其中,每一个第二URL列表中包含多条URL及每条URL对应的索引值信息,并将每一个第二URL列表存储至预设的第二URL列表的存储路径中,即,第三预设存储路径中。
在该步骤中,第二URL列表的数量与第二应用容器的数量一致,例如,第二应用容器的数量为5时,N为5,表示将第一URL列表划分为5各第二URL列表。基于该步骤,实现待爬取列表及对应的程序索引值的划分及转移。
进一步地,第一应用容器从第二预设存储路径调用配置文件,将服务器 的CPU资源分配给下述多个第二应用容器,供多个第二应用容器并行地执行网页数据爬取操作。从该配置文件中获取数据处理参数,其中,数据处理参数包括并行进程的数量N以及爬取到的网页数据的存储路径。
A4、基于所述多个第二应用容器分别爬取所述多个第二URL列表中每条URL对应的网页数据,并将该网页数据保存至第四预设存储路径中;
同步地运行所述N个第二应用容器,一个第二应用容器对应于的一个第二URL列表,所述多个第二应用容器分别从所述第三预设存储路径获取一个第二URL列表,根据每一个第二URL列表中每条URL对应的索引值,依次调用与索引值对应的爬虫程序,进行网页数据爬取操作,并将爬取到的网页数据保存至指定的存储路径中。其中,不同的第二应用容器对应同一个第四预设存储路径,即,不同第二应用内容器爬取到的网页数据保存至同一个文件夹中。通过该步骤,实现了网页数据的爬取及汇总过程。
A5、基于所述第三应用容器从第四预设存储路径中提取所述网页数据,并将所述网页数据发送至所述网页数据爬取请求对应的用户终端。
运行所述第三应用容器,从第四预设存储路径中读取上述N个第二应用容器爬取到的网页数据,并将网页数据发送至上述网页数据爬取请求对应的用户终端,并生成提示信息。
在其他实施例中,为了保证爬取到的网页数据的完整性,需对爬取到的网页数据进行验证。具体地,所述网页数据爬取程序10被所述处理器执行时,在步骤A5之前,还实现如下步骤:
对所述网页数据的数量及第一URL列表中URL的数量进行比对,确定第三URL列表;
当第三URL列表不为空时,针对第三URL列表中的每条URL执行网页数据爬取操作,直至第三URL列表为空为止,并将所述第三URL列表对应的网页数据保存至第四预设存储路径中;
当第三URL列表为空时,继续执行步骤A5。
具体地,基于docker镜像生成第四应用容器,该第四应用容器对爬取到的网页数据进行验证。其中,第三URL列表中包含待爬取的URL及待爬取URL对应的索引值。可以理解的是,一条URL对应一条网页数据,假设统计得到第一URL列表中URL的数量为P、第四预设存储路径中网页数据的数量 为Q,当P=Q时,说明第三URL列表为空,即不存在未处理的URL,也就是说,不存在待爬取的网页数据;当P>Q时,所述第三URL列表中URL的数量为P-Q,P-Q条URL为待处理的URL,即存在待爬取的网页数据,对于包含待处理URL的第三URL列表,运行上述第四应用容器,执行网页数据爬取操作,并将该步骤爬取到的网页数据与通过步骤A4爬取到的网页数据进行合并。需要说明是,当对第三URL列表中的URL执行预设次数(例如,3次)后,某URL仍然存在在第三URL列表中时,生成预警信息。通过该步骤,可以防止网页数据的遗漏,保证网页数据的完整性。
优选地,存在一种情况,爬取到的网页数据中包含子URL,为了保证爬取到的网页数据的全面性,还可以对第一URL列表进行深度挖掘,确定网页数据中包含的子URL对应的网页数据。具体地,具体地,所述网页数据爬取程序10被所述处理器执行时,在步骤A5之前,还实现如下步骤:
分别从第三预设存储路径中获取第二URL列表及URL正则挖掘程序;
从第四预设存储路径中获取各第二URL列表对应的网页数据,对各第二URL列表对应的网页数据进行挖掘,确定每个第二URL列表对应的第四URL列表,将所述第四URL列表保存至第五预设存储路径中;
对所述第四URL列表执行网页数据爬取操作,继续对第四URL列表对应的网页数据进行子URL挖掘操作,抽取新的子URL,并进行网页数据爬取操作,以此循环。
每个第二URL列表对应一个第四URL列表,对第四URL列表执行网页数据爬取操作的第二应用容器与该第四URL列表对应的第二URL列表的第二应用容器为同一个。
需要理解的是,为了防止一直深度挖掘新的子URL的情况,预先设置一个深度阈值(表示深度挖掘子URL的次数),当深度挖掘URL列表的次数超过预设的深度阈值时,停止挖掘新的子URL的操作。
上述实施例提出的电子装置1,基于docker镜像建立docker应用容器来并行的进行数据处理,docker应用容器可以节省启动操作系统所带来的资源浪费,以进程级别的消耗来提供与虚拟机类似的隔离能力,基于这个框架,用户只需要设置好配置文件、将相关程序生成镜像文件,通过建立多个docker应用容器并行地爬取网页数据,即可高效地完成网页数据爬取工作;通过对 爬取到的网页数据进行数据验证,保证爬取到的网页数据的完整性;通过对爬取到的网页数据进行子URL深度挖掘,保证网页数据的全面性。
可选地,在其他的实施例中,网页数据爬取程序10还可以被分割为一个或者多个模块,一个或者多个模块被存储于存储器11中,并由一个或多个处理器(本实施例为处理器12)所执行,以完成本申请,本申请所称的模块是指能够完成特定功能的一系列计算机程序指令段。例如,参照图3所示,为图2中网页数据爬取程序10的模块示意图,该实施例中,网页数据爬取程序10可以被分割为接收模块110、容器生成模块120、列表划分模块130、数据爬取模块140及数据发送模块150,所述模块110-150所实现的功能或操作步骤均与上文类似,此处不再详述,示例性地,例如其中:
接收模块110,用于接收网页数据爬取请求,根据该网页数据爬取请求获取第一URL列表,该第一URL列表中包括待爬取的URL,将该第一URL列表存储至预设的配置文件所在的第一预设存储路径中;
容器生成模块120,用于从第二预设存储路径中读取预先构建的docker镜像,并根据所述docker镜像生成多个应用容器,其中,应用容器包括:第一应用容器、第二应用容器、第三应用容器;及
列表划分模块130,用于从所述第一预设存储路径中读取第一URL列表及配置文件,基于所述第一应用容器将所述第一URL列表划分为多个第二URL列表,将所述多个第二URL列表存储至第三预设存储路径中;
数据爬取模块140,用于基于所述多个第二应用容器分别爬取所述多个第二URL列表中每条URL对应的网页数据,并将该网页数据保存至第四预设存储路径中;及
数据发送模块150,用于基于所述第三应用容器从第四预设存储路径中提取所述网页数据,并将所述网页数据发送至所述网页数据爬取请求对应的用户终端。
此外,本申请实施例还提出一种计算机可读存储介质,所述计算机可读存储介质中包括网页数据爬取程序10,所述网页数据爬取程序10被处理器执行时实现如下操作:
A1、接收网页数据爬取请求,根据该网页数据爬取请求获取第一URL列表,该第一URL列表中包括待爬取的URL,将该第一URL列表存储至预设的配置文件所在的第一预设存储路径中;
A2、从第二预设存储路径中读取预先构建的docker镜像,并根据所述docker镜像生成多个应用容器,其中,应用容器包括:第一应用容器、第二应用容器、第三应用容器;
A3、从所述第一预设存储路径中读取第一URL列表及配置文件,基于所述第一应用容器将所述第一URL列表划分为多个第二URL列表,将所述多个第二URL列表存储至第三预设存储路径中;
A4、基于所述多个第二应用容器分别爬取所述多个第二URL列表中每条URL对应的网页数据,并将该网页数据保存至第四预设存储路径中;及
A5、基于所述第三应用容器从第四预设存储路径中提取所述网页数据,并将所述网页数据发送至所述网页数据爬取请求对应的用户终端。
本申请之计算机可读存储介质的具体实施方式与上述网页数据爬取方法的具体实施方式大致相同,在此不再赘述。
上述本申请实施例序号仅仅为了描述,不代表实施例的优劣。
需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、装置、物品或者方法不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、装置、物品或者方法所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、装置、物品或者方法中还存在另外的相同要素。
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在如上所述的一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,或者网络设备等)执行本申请各个实施例所述的方法。
以上仅为本申请的优选实施例,并非因此限制本申请的专利范围,凡是利用本申请说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其它相关的技术领域,均同理包括在本申请的专利保护范围内。

Claims (20)

  1. 一种网页数据爬取方法,应用于电子装置,其特征在于,所述方法包括:
    S1、接收网页数据爬取请求,根据该网页数据爬取请求获取第一URL(Uniform Resource Location,统一资源定位符)列表,该第一URL列表中包括待爬取的URL,将该第一URL列表存储至预设的配置文件所在的第一预设存储路径中;
    S2、从第二预设存储路径中读取预先构建的应用容器引擎镜像,并根据所述docker镜像生成多个应用容器,其中,应用容器包括:第一应用容器、第二应用容器、第三应用容器;
    S3、从所述第一预设存储路径中读取第一URL列表及配置文件,基于所述第一应用容器将所述第一URL列表划分为多个第二URL列表,将所述多个第二URL列表存储至第三预设存储路径中;
    S4、基于所述多个第二应用容器分别爬取所述多个第二URL列表中每条URL对应的网页数据,并将该网页数据保存至第四预设存储路径中;及
    S5、基于所述第三应用容器从第四预设存储路径中提取所述网页数据,并将所述网页数据发送至所述网页数据爬取请求对应的用户终端。
  2. 根据权利要求1所述的网页数据爬取方法,其特征在于,在步骤S1之前,该方法还包括:
    接收客户端发送的配置参数,从配置参数中获取预先配置好并行进程的数量、网页数据及各程序的指定存储路径;及
    根据获取的并行进程的数量、各个程序的文件路径生成配置文件,将所述配置文件存储至第一预设存储路径中。
  3. 根据权利要求2所述的网页数据爬取方法,其特征在于,在步骤S5之前,该方法还包括以下步骤:
    对所述网页数据的数量及第一URL列表中URL的数量进行比对,确定第三URL列表;
    当第三URL列表不为空时,针对第三URL列表中的每条URL执行网页数据爬取操作,直至第三URL列表为空为止,并将所述第三URL列表对应的网页数据保存至第四预设存储路径中;及
    当第三URL列表为空时,继续执行步骤S5。
  4. 根据权利要求1所述的网页数据爬取方法,其特征在于,所述第一URL列表中还包括每条URL对应的索引值信息,其中,所述“每条URL对应的索引值信息”通过以下步骤获取:
    获取并分析第一URL列表中每条URL的具体信息,确定每条URL的特征信息;及
    根据特征信息与索引值的映射关系,为第一URL列表中每条URL匹配对应的索引值。
  5. 根据权利要求4所述的网页数据爬取方法,其特征在于,该方法还包括以下步骤:
    当存在无法根据特征信息匹配索引值的URL时,基于该URL生成提示信息,并接收对该URL匹配索引值的匹配指令。
  6. 根据权利要求5所述的网页数据爬取方法,其特征在于,在步骤S5之前,该方法还包括以下步骤:
    对所述网页数据的数量及第一URL列表中URL的数量进行比对,确定第三URL列表;
    当第三URL列表不为空时,针对第三URL列表中的每条URL执行网页数据爬取操作,直至第三URL列表为空为止,并将所述第三URL列表对应的网页数据保存至第四预设存储路径中;及
    当第三URL列表为空时,继续执行步骤S5。
  7. 根据权利要求6所述的网页数据爬取方法,其特征在于,在步骤S5之前,该方法还包括以下步骤:
    分别从第三预设存储路径中获取第二URL列表及URL正则挖掘程序;
    从第四预设存储路径中获取各第二URL列表对应的网页数据,对各第二URL列表对应的网页数据进行挖掘,确定每个第二URL列表对应的第四URL列表,将所述第四URL列表保存至第五预设存储路径中;及
    对所述第四URL列表执行网页数据爬取操作,并对第四URL列表对应的网页数据进行子URL挖掘操作,抽取新的子URL,并进行网页数据爬取操作,以此循环。
  8. 一种电子装置,其特征在于,该装置包括:存储器、处理器,所述存储器上存储有可在所述处理器上运行的网页数据爬取程序,所述网页数据爬 取程序被所述处理器执行时,可实现如下步骤:
    A1、接收网页数据爬取请求,根据该网页数据爬取请求获取第一URL列表,该第一URL列表中包括待爬取的URL,将该第一URL列表存储至预设的配置文件所在的第一预设存储路径中;
    A2、从第二预设存储路径中读取预先构建的docker镜像,并根据所述docker镜像生成多个应用容器,其中,应用容器包括:第一应用容器、第二应用容器、第三应用容器;
    A3、从所述第一预设存储路径中读取第一URL列表及配置文件,基于所述第一应用容器将所述第一URL列表划分为多个第二URL列表,将所述多个第二URL列表存储至第三预设存储路径中;
    A4、基于所述多个第二应用容器分别爬取所述多个第二URL列表中每条URL对应的网页数据,并将该网页数据保存至第四预设存储路径中;及
    A5、基于所述第三应用容器从第四预设存储路径中提取所述网页数据,并将所述网页数据发送至所述网页数据爬取请求对应的用户终端。
  9. 根据权利要求8所述的电子装置,其特征在于,所述网页数据爬取程序被所述处理器执行时,在步骤A1之前,还实现如下步骤:
    接收客户端发送的配置参数,从配置参数中获取预先配置好并行进程的数量、网页数据及各程序的指定存储路径;及
    根据获取的并行进程的数量、各个程序的文件路径生成配置文件,将所述配置文件存储至第一预设存储路径中。
  10. 根据权利要求9所述的电子装置,其特征在于,所述网页数据爬取程序被所述处理器执行时,在步骤A5之前,还实现如下步骤:
    对所述网页数据的数量及第一URL列表中URL的数量进行比对,确定第三URL列表;
    当第三URL列表不为空时,针对第三URL列表中的每条URL执行网页数据爬取操作,直至第三URL列表为空为止,并将所述第三URL列表对应的网页数据保存至第四预设存储路径中;及
    当第三URL列表为空时,继续执行步骤A5。
  11. 根据权利要求8所述的电子装置,其特征在于,所述第一URL列表中还包括每条URL对应的索引值信息,其中,所述“每条URL对应的索引值 信息”通过以下步骤获取:
    获取并分析第一URL列表中每条URL的具体信息,确定每条URL的特征信息;及
    根据特征信息与索引值的映射关系,为第一URL列表中每条URL匹配对应的索引值。
  12. 根据权利要求11所述的电子装置,其特征在于,所述网页数据爬取程序被所述处理器执行时,还实现如下步骤:
    当存在无法根据特征信息匹配索引值的URL时,基于该URL生成提示信息,并接收对该URL匹配索引值的匹配指令。
  13. 根据权利要求12所述的电子装置,其特征在于,所述网页数据爬取程序被所述处理器执行时,在步骤A5之前,还实现如下步骤:
    对所述网页数据的数量及第一URL列表中URL的数量进行比对,确定第三URL列表;
    当第三URL列表不为空时,针对第三URL列表中的每条URL执行网页数据爬取操作,直至第三URL列表为空为止,并将所述第三URL列表对应的网页数据保存至第四预设存储路径中;及
    当第三URL列表为空时,继续执行步骤S5。
  14. 根据权利要求13所述的电子装置,其特征在于,所述网页数据爬取程序被所述处理器执行时,在步骤A5之前,还实现如下步骤:
    分别从第三预设存储路径中获取第二URL列表及URL正则挖掘程序;
    从第四预设存储路径中获取各第二URL列表对应的网页数据,对各第二URL列表对应的网页数据进行挖掘,确定每个第二URL列表对应的第四URL列表,将所述第四URL列表保存至第五预设存储路径中;
    对所述第四URL列表执行网页数据爬取操作,继续对第四URL列表对应的网页数据进行子URL挖掘操作,抽取新的子URL,并进行网页数据爬取操作,以此循环。
  15. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质中包括网页数据爬取程序,所述网页数据爬取程序被处理器执行时,可实现如下步骤:
    A1、接收网页数据爬取请求,根据该网页数据爬取请求获取第一URL列 表,该第一URL列表中包括待爬取的URL,将该第一URL列表存储至预设的配置文件所在的第一预设存储路径中;
    A2、从第二预设存储路径中读取预先构建的docker镜像,并根据所述docker镜像生成多个应用容器,其中,应用容器包括:第一应用容器、第二应用容器、第三应用容器;
    A3、从所述第一预设存储路径中读取第一URL列表及配置文件,基于所述第一应用容器将所述第一URL列表划分为多个第二URL列表,将所述多个第二URL列表存储至第三预设存储路径中;
    A4、基于所述多个第二应用容器分别爬取所述多个第二URL列表中每条URL对应的网页数据,并将该网页数据保存至第四预设存储路径中;及
    A5、基于所述第三应用容器从第四预设存储路径中提取所述网页数据,并将所述网页数据发送至所述网页数据爬取请求对应的用户终端。
  16. 根据权利要求15所述的计算机可读存储介质,其特征在于,所述网页数据爬取程序被所述处理器执行时,在步骤A1之前,还实现如下步骤:
    接收客户端发送的配置参数,从配置参数中获取预先配置好并行进程的数量、网页数据及各程序的指定存储路径;及
    根据获取的并行进程的数量、各个程序的文件路径生成配置文件,将所述配置文件存储至第一预设存储路径中。
  17. 根据权利要求16所述的计算机可读存储介质,其特征在于,所述第一URL列表中还包括每条URL对应的索引值信息,其中,所述“每条URL对应的索引值信息”通过以下步骤获取:
    获取并分析第一URL列表中每条URL的具体信息,确定每条URL的特征信息;及
    根据特征信息与索引值的映射关系,为第一URL列表中每条URL匹配对应的索引值。
  18. 根据权利要求17所述的计算机可读存储介质,其特征在于,所述网页数据爬取程序被所述处理器执行时,还实现如下步骤:
    当存在无法根据特征信息匹配索引值的URL时,基于该URL生成提示信息,并接收对该URL匹配索引值的匹配指令。
  19. 根据权利要求18所述的计算机可读存储介质,其特征在于,所述网 页数据爬取程序被所述处理器执行时,在步骤A5之前,还实现如下步骤:
    对所述网页数据的数量及第一URL列表中URL的数量进行比对,确定第三URL列表;
    当第三URL列表不为空时,针对第三URL列表中的每条URL执行网页数据爬取操作,直至第三URL列表为空为止,并将所述第三URL列表对应的网页数据保存至第四预设存储路径中;及
    当第三URL列表为空时,继续执行步骤S5。
  20. 根据权利要求19所述的计算机可读存储介质,其特征在于,所述网页数据爬取程序被所述处理器执行时,在步骤A5之前,还实现如下步骤:
    分别从第三预设存储路径中获取第二URL列表及URL正则挖掘程序;
    从第四预设存储路径中获取各第二URL列表对应的网页数据,对各第二URL列表对应的网页数据进行挖掘,确定每个第二URL列表对应的第四URL列表,将所述第四URL列表保存至第五预设存储路径中;
    对所述第四URL列表执行网页数据爬取操作,继续对第四URL列表对应的网页数据进行子URL挖掘操作,抽取新的子URL,并进行网页数据爬取操作,以此循环。
PCT/CN2018/108218 2018-07-18 2018-09-28 网页数据爬取方法、装置及存储介质 Ceased WO2020015192A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201810791126.3A CN110020060B (zh) 2018-07-18 2018-07-18 网页数据爬取方法、装置及存储介质
CN201810791126.3 2018-07-18

Publications (1)

Publication Number Publication Date
WO2020015192A1 true WO2020015192A1 (zh) 2020-01-23

Family

ID=67188354

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2018/108218 Ceased WO2020015192A1 (zh) 2018-07-18 2018-09-28 网页数据爬取方法、装置及存储介质

Country Status (2)

Country Link
CN (1) CN110020060B (zh)
WO (1) WO2020015192A1 (zh)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115203613A (zh) * 2022-07-21 2022-10-18 中国平安人寿保险股份有限公司 网页资源获取方法、装置、计算机可读存储介质
CN115658997A (zh) * 2022-10-25 2023-01-31 爱集微咨询(厦门)有限公司 网页数据采集方法、装置、终端及存储介质
CN116361362A (zh) * 2023-05-30 2023-06-30 江西顶易科技发展有限公司 一种基于网页内容识别的用户信息挖掘方法与系统
CN116415053A (zh) * 2023-03-03 2023-07-11 北京众辉科技有限公司 一种分布式网页数据采集方法、装置及电子设备

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110888655A (zh) * 2019-11-14 2020-03-17 中国民航信息网络股份有限公司 一种应用发布方法及装置
CN113392301A (zh) * 2021-06-08 2021-09-14 北京精准沟通传媒科技股份有限公司 爬取数据的方法、装置、介质及电子设备

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106101176A (zh) * 2016-05-27 2016-11-09 成都索贝数码科技股份有限公司 一种一体化的融媒体云生产发布系统与方法
CN106484886A (zh) * 2016-10-17 2017-03-08 金蝶软件(中国)有限公司 一种数据采集的方法及其相关设备
CN108062413A (zh) * 2017-12-30 2018-05-22 平安科技(深圳)有限公司 网页数据处理方法、装置、计算机设备及存储介质
CN108197633A (zh) * 2017-11-24 2018-06-22 百年金海科技有限公司 基于TensorFlow的深度学习图像分类与应用部署方法

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7676553B1 (en) * 2003-12-31 2010-03-09 Microsoft Corporation Incremental web crawler using chunks
KR20120042529A (ko) * 2010-10-25 2012-05-03 삼성전자주식회사 웹 페이지 크롤링 방법 및 장치
CN103970788A (zh) * 2013-02-01 2014-08-06 北京英富森信息技术有限公司 一种基于网页爬取的爬虫技术

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106101176A (zh) * 2016-05-27 2016-11-09 成都索贝数码科技股份有限公司 一种一体化的融媒体云生产发布系统与方法
CN106484886A (zh) * 2016-10-17 2017-03-08 金蝶软件(中国)有限公司 一种数据采集的方法及其相关设备
CN108197633A (zh) * 2017-11-24 2018-06-22 百年金海科技有限公司 基于TensorFlow的深度学习图像分类与应用部署方法
CN108062413A (zh) * 2017-12-30 2018-05-22 平安科技(深圳)有限公司 网页数据处理方法、装置、计算机设备及存储介质

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
ZHAO, LELE: "Research and Application of Full-Text Search Engine Based on Docker Technology", CHINESE MASTER’S THESES FULL-TEXT DATABASE, INFORMATION SCIENCE AND TECHNOLOGY, 15 February 2018 (2018-02-15), pages 1 - 20 *

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115203613A (zh) * 2022-07-21 2022-10-18 中国平安人寿保险股份有限公司 网页资源获取方法、装置、计算机可读存储介质
CN115658997A (zh) * 2022-10-25 2023-01-31 爱集微咨询(厦门)有限公司 网页数据采集方法、装置、终端及存储介质
CN116415053A (zh) * 2023-03-03 2023-07-11 北京众辉科技有限公司 一种分布式网页数据采集方法、装置及电子设备
CN116361362A (zh) * 2023-05-30 2023-06-30 江西顶易科技发展有限公司 一种基于网页内容识别的用户信息挖掘方法与系统
CN116361362B (zh) * 2023-05-30 2023-08-11 江西顶易科技发展有限公司 一种基于网页内容识别的用户信息挖掘方法与系统

Also Published As

Publication number Publication date
CN110020060B (zh) 2023-03-14
CN110020060A (zh) 2019-07-16

Similar Documents

Publication Publication Date Title
WO2020015192A1 (zh) 网页数据爬取方法、装置及存储介质
WO2019227715A1 (zh) 数据处理方法、装置及计算机可读存储介质
CN102236581B (zh) 用于数据中心的映射化简方法和系统
CN110737659A (zh) 图数据存储和查询方法、装置及计算机可读存储介质
CN107967135B (zh) 计算引擎实现方法、电子装置及存储介质
GB2503549A (en) Automatically associating tags with files in a computer system using search keywords.
US20180253439A1 (en) Characterizing files for similarity searching
CN112416458A (zh) 基于ReactNative的预加载方法、装置、计算机设备及存储介质
CN109885744B (zh) 网页数据爬取方法、装置、系统、计算机设备及存储介质
US11176223B1 (en) Page rendering by an intermediary system that uses a truncated library
WO2020092135A1 (en) Extracting web api endpoint data from source code
WO2019041441A1 (zh) 列表视图的更新装置、方法及计算机可读存储介质
CN111538672A (zh) 测试案例分层测试方法、计算机设备及计算机可读存储介质
CN114064032A (zh) 源代码处理方法、装置、电子设备和存储介质
CN114491646A (zh) 数据脱敏方法、装置、电子设备及存储介质
CN112528189B (zh) 基于数据的组件封装方法、装置、计算机设备及存储介质
WO2022134776A1 (zh) 基于标签的反爬虫方法、装置、计算机设备及存储介质
WO2022142008A1 (zh) 数据处理方法、装置、电子设备及存储介质
WO2020024403A1 (zh) 目标语料数据的爬取方法、装置及存储介质
CN107679022A (zh) 生僻字处理方法及其系统
CN104462158A (zh) 数据抓取方法和数据抓取系统
CN111651248A (zh) 定时任务执行方法、装置、电子设备及存储介质
US9471363B2 (en) Preemptive guest merging for virtualization hypervisors
WO2019114158A1 (zh) 实时动画显示方法、装置、电子终端及可读存储介质
CN115168760B (zh) 数据查询方法、装置及存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 18926777

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 18926777

Country of ref document: EP

Kind code of ref document: A1