WO2020024403A1 - 目标语料数据的爬取方法、装置及存储介质 - Google Patents
目标语料数据的爬取方法、装置及存储介质 Download PDFInfo
- Publication number
- WO2020024403A1 WO2020024403A1 PCT/CN2018/107489 CN2018107489W WO2020024403A1 WO 2020024403 A1 WO2020024403 A1 WO 2020024403A1 CN 2018107489 W CN2018107489 W CN 2018107489W WO 2020024403 A1 WO2020024403 A1 WO 2020024403A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- rule
- list
- target
- target information
- data
- 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
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/95—Retrieval from the web
- G06F16/953—Querying, e.g. by the use of web search engines
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/95—Retrieval from the web
- G06F16/955—Retrieval from the web using information identifiers, e.g. uniform resource locators [URL]
-
- Y—GENERAL 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
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE 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/00—Energy 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 target corpus data, an electronic device, and a computer-readable storage medium.
- the current crawling method for informational websites is to customize one-to-one crawlers based on the website, and the informational corpus basically has fixed templates for comprehensive development. If you customize and develop for all informational webpage templates, it is prone to poor scalability and The large workload greatly reduces the crawling efficiency of the corpus data.
- this application provides a method, a server, and a computer-readable storage medium for crawling target corpus data, the main purpose of which is to improve the accuracy and efficiency of crawling target corpus data.
- the present application provides a method for crawling target corpus data, which method includes:
- S1 Receive a crawl request from a user that carries target corpus data carrying an initial corpus, and determine a specified information crawl rule and target information crawl rule corresponding to the crawl request of the target corpus data;
- the present application also provides an electronic device, characterized in that the device includes: a memory and a processor, and the memory stores a crawling program of target corpus data that can be run on the processor, and the target When the crawling program of the corpus data is executed by the processor, it can implement any step in the method for crawling the target corpus data as described above.
- the present application further provides a computer-readable storage medium, where the computer-readable storage medium includes a crawling program of target corpus data, and the crawling program of the target corpus data is executed by a processor , Can implement any step in the method of crawling target corpus data as described above.
- the crawling method, electronic device, and computer-readable storage medium of the target corpus data proposed in this application after receiving a crawl request for target information, first determine a crawl rule required to crawl the target corpus, and call the crawl rule, Crawl the first title page URL list, the first list page URL list, and the first content page URL list in order, and then crawl the second list page URL list corresponding to the first title page URL list to generate the third list page URL list. Crawl the second content page URL list corresponding to the third list page URL list, generate the third content page URL list to obtain the content page data, and finally use the target information crawl rule to crawl out the target information, by determining the universally high crawl Rules to improve the crawling efficiency of the target corpus data. By obtaining more comprehensive content page data, the crawled target corpus data is more accurate.
- FIG. 1 is a flowchart of a preferred embodiment of a method for crawling target corpus data
- 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 program modules of a crawling program of target corpus data in FIG. 2 of the present application.
- FIG. 1 is a flowchart of a preferred embodiment of a method for crawling target corpus data. The method may be performed by a device, which may be implemented by software and / or hardware.
- the method for crawling target corpus data includes steps S1-S6:
- S1 Receive a crawl request from a user that carries target corpus data carrying an initial corpus, and determine a specified information crawl rule and target information crawl rule corresponding to the crawl request of the target corpus data;
- the electronic device serves as a server to establish a communication connection with a user terminal, receives a crawl request sent by the user terminal, and performs corresponding processing according to the crawl request.
- webpage data of an informational website is taken as an example, but it is not limited to webpage data of an informational website.
- the above crawl request includes: an initial corpus, a target corpus data type, a crawl path, and the like. That is, when the user submits the crawl request, he submits the target information type in the initial corpus and the target corpus data, that is, the content to be crawled, and then sends the crawl request to the electronic device through the user terminal. The device sends the crawl request to a preset client.
- the initial corpus refers to a pre-determined list of URLs (Uniform Resource Location, Uniform Resource Locator) to be crawled, for example, a list of URLs of informational web pages provided by a user when submitting a crawl request.
- URLs Uniform Resource Location, Uniform Resource Locator
- a user wants to obtain travel information from Ctrip.com: title, author, and text.
- the user must first provide a URL list of travels on Ctrip.com, get the content page of the travels according to the URL list, and then get the title, author, and text from the content page of the travels. information.
- the preset client is a terminal used by the crawler engineer. After receiving the crawl request, the preset general framework of the crawler is called, and the category is obtained according to the category (for example, information category) of the required content in the crawl request.
- the crawler engineer configures parameters that need to be adjusted manually, for example, CPU resource allocation, storage path of crawled data, etc., which are not described here. Then save the parameter configuration to the configuration file in the preset path.
- the configuration file is an XML file.
- the configuration file further includes a rule base, and the rule base includes a specified information capture rule and a target information capture rule.
- the above-mentioned crawling rules are related to the specific content of the crawl request. If the target information to be crawled by the user is the title, author, and text, then the crawling rules to be used in the process of crawling the target information need to be determined in advance. , Including specified information fetching rules and target information fetching rules, among which the specified information fetching rules include: title page fetching rules, list page fetching rules, content page fetching rules, target information fetching rules include: title fetching Fetch rules, author fetch rules, body fetch rules.
- all crawling rules are implemented through regular expressions, that is, the rule base includes: title page regular expressions, list page regular expressions, content page regular expressions, title regular expressions, and author regular expressions. Expression, body regular expression.
- the target information capture rule is obtained through the following steps:
- Annotate the target information of the specified webpage data generate a target information data set, and determine the mapping relationship between the target information data set and the initial crawling rule;
- a5 When the matching rate is greater than or equal to a preset threshold, use the initial capture rule as a target information capture rule; when the matching rate is less than the preset threshold, receive an adjustment instruction to the initial capture rule, and return Go to step a3.
- a regular expression list of the website template is provided in advance for the reference of the crawler engineer.
- the initial regular expression corresponding to the target information is determined. , That is, the initial crawl rule, and the initial crawl rule of the target information is saved to the specified path.
- the regular expressions corresponding to the same target content are also different. Therefore, the crawler engineer needs to adjust according to the crawl request.
- the initial crawling rules include: initial headline crawling rules, initial body crawling rules, and initial author crawling rules.
- the specified webpage data may be webpage data whose webpage type is the same as that of the URL in the initial corpus, or webpage data corresponding to a preset proportion of URLs in the URL list in the initial corpus.
- the specified data is webpage data corresponding to a preset proportion of URLs in the URL list in the initial corpus, randomly extract a preset proportion (for example, 10%) of the URLs from the URL list in the initial corpus and crawl its corresponding Web page data is used as designated web page data.
- the target information is a title
- the title in each web page data is extracted from the designated web page data to generate a target title data set [X1, X2, X3, Xi, ..., Xn], where Xi represents the designated web page data
- the actual title of one of the web page's data corresponds to the initial title fetching rule.
- the target information can also be the text and author of the specified web page data.
- the title that is, the title information extracted using the extraction rule, may or may not be the actual title information.
- step a4 can be refined into the following steps:
- the target title information of the web page data is the same as the real-time title information; otherwise, it is determined that the target title information of the i-th web page data is different from the real-time title information.
- M is the number of designated webpage data with the same target information and real-time information
- T is the total number of designated webpage data.
- a threshold for example, 80% is set in advance.
- the matching rate is greater than or equal to 80%, it is judged that the corresponding initial crawling rule is more universal. Therefore, this initial crawling rule is used as the target crawling rule and saved.
- the matching rate is less than 80%, it is judged that the corresponding initial crawling rule is less universal, and based on the initial crawling rule, a prompt is generated and fed back to a preset terminal for the crawler engineer to adjust the initial crawling rule.
- the adjustment instruction includes the adjusted initial crawling rule, and then repeat steps a3 to a5.
- the specified information grabbing rules in the rule base can also be obtained through the above steps, which will not be described here.
- the first title page URL list is fetched using a title page regular expression
- the first list page URL list is fetched using a list page regular expression
- the first content page URL list is fetched using a content page regular expression.
- the list page web page source code is obtained, and the corresponding second content page URL list is grabbed from the web page source code, and is compared with the first content page URL list. And merge to get a more comprehensive URL list of the third content page in the same industry URL.
- a crawler program is called to crawl the data corresponding to each content page URL in the third content page URL list obtained through the above steps to generate first corpus data.
- the specified information capture rule further includes a target information denoising rule
- step S6 further includes:
- a preset target information denoising rule is invoked to perform denoising processing on the target information to determine target corpus data.
- the target information denoising rule includes: a title denoising rule, an author denoising rule, and a text denoising rule, that is, a title denoising regular expression, an author denoising regular expression, and a text denoising regular expression. .
- Use heading denoising regular expression to denoise the target title information use author denoising regular expression to denoise the target author information, and use body denoising regular expression to denoise the target body information.
- the cleaned corpus data is then saved as target corpus data in the target corpus, and the target corpus is fed back to the user.
- the method for crawling target corpus data after receiving a crawl request for target information, first determines the crawl rules required to crawl the target corpus, invokes the crawl rules, and sequentially crawls the first title page URL List, first list page URL list, and first content page URL list, then crawl the second list page URL list corresponding to the first title page URL list, generate a third list page URL list, and crawl the third list page URL list Corresponding second content page URL list, generate third content page URL list to obtain content page data, and finally use target information crawling rules to crawl target information.
- By determining universally high crawling rules improve the target corpus data. Crawling efficiency makes the target corpus data crawled more accurate by obtaining more comprehensive content 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 crawling program 10 of target corpus data, 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 the crawler 10 of the target corpus data.
- CPU central processing unit
- controller a controller
- microcontroller a microcontroller
- 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 the crawler 10 of the target corpus data.
- 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-controlled 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 crawling program 10 of target corpus data is stored in a memory 11 as a computer storage medium, and the processor 12 executes a crawling program of target corpus data stored in the memory 11.
- the following steps are implemented:
- A1. Receive a crawl request from a user that carries target corpus data carrying an initial corpus, and determine a specified information crawl rule and target information crawl rule corresponding to the crawl request of the target corpus data;
- the electronic device serves as a server to establish a communication connection with the user terminal, receives a crawl request sent by the user terminal, and performs corresponding processing according to the crawl request.
- webpage data of an informational website is taken as an example, but it is not limited to webpage data of an informational website.
- the above crawl request includes: an initial corpus, a target corpus data type, a crawl path, and the like. That is, when the user submits the crawl request, he submits the target information type in the initial corpus and the target corpus data, that is, the content to be crawled, and then sends the crawl request to the electronic device through the user terminal. The device sends the crawl request to a preset client.
- the initial corpus refers to a predetermined list of web page URLs to be crawled, for example, an informational web page URL list provided by the user when submitting a crawl request. Through the URL list of web pages in the initial corpus, you can get the title page, list page, and content page of each web page.
- a user wants to obtain travel information from Ctrip.com: title, author, and text.
- the user must first provide a URL list of travels in Ctrip.com, and obtain the content page of the travels according to the URL list, and then obtain the title, author, and Text information.
- the preset client is a terminal used by the crawler engineer. After receiving the crawl request, the preset general framework of the crawler is called, and the category is obtained according to the category (for example, information category) of the required content in the crawl request.
- the crawler engineer configures parameters that need to be adjusted manually, for example, CPU resource allocation, storage path of crawled data, etc., which are not described here. Then save the parameter configuration to the configuration file in the preset path.
- the configuration file is an XML file.
- the configuration file further includes a rule base, and the rule base includes a specified information capture rule and a target information capture rule.
- the above-mentioned crawling rules are related to the specific content of the crawl request. If the target information to be crawled by the user is the title, author, and text, then the crawling rules to be used in the process of crawling the target information need to be determined .
- all crawling rules are implemented through regular expressions, that is, the rule base includes: title page regular expressions, list page regular expressions, content page regular expressions, title regular expressions, and author regular expressions. Expression, body regular expression.
- the target information capture rule is obtained through the following steps:
- Annotate the target information of the specified webpage data generate a target information data set, and determine the mapping relationship between the target information data set and the initial crawling rule;
- a5 When the matching rate is greater than or equal to a preset threshold, use the initial capture rule as a target information capture rule; when the matching rate is less than the preset threshold, receive an adjustment instruction to the initial capture rule, and return Go to step a3.
- a regular expression list of the website template is provided in advance for the reference of the crawler engineer.
- the initial regular expression corresponding to the target information is determined. , That is, the initial crawl rule, and the initial crawl rule of the target information is saved to the specified path.
- the regular expressions corresponding to the same target content are also different. Therefore, the crawler engineer needs to adjust according to the crawl request.
- the initial crawling rules include: initial headline crawling rules, initial body crawling rules, and initial author crawling rules.
- the specified webpage data may be webpage data whose webpage type is the same as that of the URL in the initial corpus, or webpage data corresponding to a preset proportion of URLs in the URL list in the initial corpus.
- the specified data is webpage data corresponding to a preset proportion of URLs in the URL list in the initial corpus, randomly extract a preset proportion (for example, 10%) of the URLs from the URL list in the initial corpus and crawl its corresponding Web page data is used as designated web page data.
- the target information is a title
- the title in each web page data is extracted from the designated web page data to generate a target title data set [X1, X2, X3, Xi, ..., Xn], where Xi represents the designated web page data
- the actual title of one of the web page's data corresponds to the initial title fetching rule.
- the target information can also be the text and author of the specified web page data.
- the title that is, the title information extracted using the extraction rule, may or may not be the actual title information.
- step a4 can be refined into the following steps:
- the target title information of the web page data is the same as the real-time title information; otherwise, it is determined that the target title information of the i-th web page data is different from the real-time title information.
- M is the number of designated webpage data with the same target information and real-time information
- T is the total number of designated webpage data.
- a threshold for example, 80% is set in advance.
- the matching rate is greater than or equal to 80%, it is judged that the corresponding initial crawling rule is more universal. Therefore, this initial crawling rule is used as the target crawling rule and saved.
- the matching rate is less than 80%, it is judged that the corresponding initial crawling rule is less universal, and based on the initial crawling rule, a prompt is generated and fed back to a preset terminal for the crawler engineer to adjust the initial crawling rule.
- the adjustment instruction includes the adjusted initial crawling rule, and then repeat steps a3 to a5.
- the specified information grabbing rules in the rule base can also be obtained through the above steps, which will not be described here.
- the first title page URL list is fetched using a title page regular expression
- the first list page URL list is fetched using a list page regular expression
- the first content page URL list is fetched using a content page regular expression.
- A5 Combine the first content page URL list and the second content page URL list to generate a third content page URL list, grab content page data corresponding to the third content page URL list, and generate first corpus data;
- the list page web page source code is obtained, and the corresponding second content page URL list is grabbed from the web page source code, and is compared with the first content page URL list. And merge to get a more comprehensive URL list of the third content page in the same industry URL.
- a crawler program is invoked to crawl data corresponding to each content page URL in the third content page URL list obtained through the above steps to generate first corpus data.
- A6 Invoking the target information capture rule, capturing target information from the first corpus data, determining target corpus data, and sending the target corpus data to a user.
- the specified information capture rule further includes a target information denoising rule
- step A6 further includes:
- a preset target information denoising rule is invoked to perform denoising processing on the target information to determine target corpus data.
- the target information denoising rule includes: a title denoising rule, an author denoising rule, and a text denoising rule, that is, a title denoising regular expression, an author denoising regular expression, and a text denoising regular expression. .
- Use heading denoising regular expression to denoise the target title information use author denoising regular expression to denoise the target author information, and use body denoising regular expression to denoise the target body information.
- the cleaned corpus data is then saved as target corpus data in the target corpus, and the target corpus is fed back to the user.
- the electronic device 1 after receiving a crawl request for target information, first determines a crawl rule required to crawl the target corpus, invokes the crawl rule, and crawls the first title page URL list, the first List page URL list and first content page URL list, then crawl the second list page URL list corresponding to the first title page URL list, generate a third list page URL list, and crawl the second list page URL list corresponding to the second Content page URL list, generate the third content page URL list to obtain the content page data, and finally use the target information crawl rule to crawl out the target information.
- determining a universally high crawl rule improve the crawling efficiency of the target corpus data.
- the crawled target corpus data is more accurate.
- the crawling program 10 of the target corpus data may also be divided into one or more modules, and the one or more modules are stored in the memory 11 and processed by one or more processors. (This embodiment is executed by the processor 12) to complete the present application.
- the modules referred to in the present application refer to a series of computer program instruction segments capable of performing specific functions.
- FIG. 3 it is a schematic block diagram of a crawling program 10 of target corpus data in FIG. 2.
- the crawling program 10 of target corpus data may be divided into a receiving module 110 and a first crawling module 120, the second grabbing module 130, the third grabbing module 140, the fourth grabbing module 150, and the sending module 160.
- the functions or operation steps implemented by the modules 110-160 are similar to the above, and are not repeated here. Detailed, for example, for example:
- the receiving module 110 is configured to receive a crawl request from a user that carries target corpus data carrying an initial corpus, and determine a specified information crawl rule and a target information crawl rule corresponding to the crawl request of the target corpus data;
- the first crawling module 120 is configured to read a title page crawling rule, a list page crawling rule, and a content page crawling rule in the specified information crawling rule, and respectively extract URLs in the initial corpus ( Uniform Resource Location (Uniform Resource Locator) list corresponding to the first title page URL list, the first list page URL list, and the first content page URL list;
- Uniform Resource Location Uniform Resource Locator
- a second fetching module 130 configured to access the title page in the first title page URL list, invoke the list page scraping rule, and fetch the second list page URL list corresponding to the first title page URL list;
- the third fetching module 140 is configured to combine the first list page URL list and the second list page URL list to generate a third list page URL list, invoke the content page crawl rule, and fetch the first URL list of the second content page corresponding to the three list page URL list;
- a fourth fetching module 150 is configured to combine the first content page URL list and the second content page URL list to generate a third content page URL list, and capture content page data corresponding to the third content page URL list To generate first corpus data;
- the sending module 160 is configured to invoke the target information capture rule, capture target information from the first corpus data, determine target corpus data, and send the target corpus data to a user.
- an embodiment of the present application further provides a computer-readable storage medium, where the computer-readable storage medium includes a crawling program 10 of target corpus data, and the crawling program 10 of the target corpus data is implemented when executed by a processor.
- the computer-readable storage medium includes a crawling program 10 of target corpus data, and the crawling program 10 of the target corpus data is implemented when executed by a processor.
- A1. Receive a crawl request from a user that carries target corpus data carrying an initial corpus, and determine a specified information crawl rule and target information crawl rule corresponding to the crawl request of the target corpus data;
- A5 Combine the first content page URL list and the second content page URL list to generate a third content page URL list, grab content page data corresponding to the third content page URL list, and generate first corpus data;
- A6 Invoking the target information capture rule, capturing target information from the first corpus data, determining target corpus data, and sending the target corpus data to a user.
- the specific implementation manner of the computer-readable storage medium of the present application is substantially the same as the specific implementation manner of the above-mentioned target corpus data crawling method, and details are not described herein again.
- 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 for causing 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 the present 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 Retrieval, Db Structures And Fs Structures Therefor (AREA)
- Information Transfer Between Computers (AREA)
Abstract
一种目标语料数据的爬取方法,该方法在接收到目标信息的爬取请求后,首先确定爬取目标语料所需的爬取规则,调用爬取规则,依次从初始语料库中爬取第一标题页URL列表、第一列表页URL列表及第一内容页URL列表,然后爬取第一标题页URL列表对应的第二列表页URL列表,生成第三列表页URL列表,爬取第三列表页URL列表对应的第二内容页URL列表,生成第三内容页URL列表,以获取内容页数据,最后利用目标信息爬取规则爬取出目标信息,生成目标语料数据。还提供一种电子装置及计算机存储介质。利用上述方法,可以提高爬取目标语料数据的效率及准确性。
Description
本申请基于巴黎公约申明享有2018年8月3日递交的申请号为CN 201810876287.2、名称为“目标语料数据的爬取方法、装置及存储介质”的中国专利申请的优先权,该中国专利申请的整体内容以参考的方式结合在本申请中。
本申请涉及数据处理领域,尤其涉及一种目标语料数据的爬取方法、电子装置及计算机可读存储介质。
现有资讯类网站爬取的方式是根据网站一对一定制爬虫程序,而资讯类的语料库基本有固定的模板进行综合开发,若针对所有的资讯类网页模板进行定制开发,容易出现扩展性差和工作量大的情况,极大的降低了语料数据的爬取效率。
发明内容
鉴于以上内容,本申请提供一种目标语料数据的爬取方法、服务器及计算机可读存储介质,其主要目的在于提高目标语料数据的爬取准确性和效率。
为实现上述目的,本申请提供一种目标语料数据的爬取方法,该方法包括:
S1、接收用户提出的携带初始语料库的目标语料数据的爬取请求,确定所述目标语料数据的爬取请求对应的指定信息抓取规则及目标信息抓取规则;
S2、读取所述指定信息抓取规则中的标题页抓取规则、列表页抓取规则及内容页抓取规则,分别抓取出所述初始语料库中的URL(Uniform Resource Location,统一资源定位符)列表对应的第一标题页URL列表、第一列表页URL列表及第一内容页URL列表;
S3、访问第一标题页URL列表中的标题页,调用所述列表页抓取规则,抓取出所述第一标题页URL列表对应的第二列表页URL列表;
S4、合并所述第一列表页URL列表及所述第二列表页URL列表生成第三列表页URL列表,调用所述内容页抓取规则,抓取出所述第三列表页URL列表对应的第二内容页URL列表;
S5、合并所述第一内容页URL列表及所述第二内容页URL列表生成第三内容页URL列表,抓取所述第三内容页URL列表对应的内容页数据,生成第一语料数据;及
S6、调用所述目标信息抓取规则,从所述第一语料数据中抓取目标信息,确定目标语料数据,将所述目标语料数据发送给用户。
此外,本申请还提供一种电子装置,其特征在于,该装置包括:存储器、处理器,所述存储器上存储有可在所述处理器上运行的目标语料数据的爬取程序,所述目标语料数据的爬取程序被所述处理器执行时,可实现如上所述目标语料数据的爬取方法中的任意步骤。
此外,为实现上述目的,本申请还提供一种计算机可读存储介质,所述计算机可读存储介质中包括目标语料数据的爬取程序,所述目标语料数据的爬取程序被处理器执行时,可实现如上所述目标语料数据的爬取方法中的任意步骤。
本申请提出的目标语料数据的爬取方法、电子装置及计算机可读存储介质,在接收到目标信息的爬取请求后,首先确定爬取目标语料所需的爬取规则,调用爬取规则,依次爬取第一标题页URL列表、第一列表页URL列表及第一内容页URL列表,然后爬取第一标题页URL列表对应的第二列表页URL列表,生成第三列表页URL列表,爬取第三列表页URL列表对应的第二内容页URL列表,生成第三内容页URL列表,以获取内容页数据,最后利用目标信息爬取规则爬取出目标信息,通过确定普适度高的爬取规则,提高目标语料数据的爬取效率,通过获取更全面的内容页数据,使爬取的目标语料数据更准确。
图1为本申请目标语料数据的爬取方法较佳实施例的流程图;
图2为本申请电子装置较佳实施例的示意图;
图3为本申请图2中目标语料数据的爬取程序的程序模块示意图。
本申请目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。
应当理解,此处所描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。
本申请提供一种目标语料数据的爬取方法。参照图1所示,为本申请目标语料数据的爬取方法较佳实施例的流程图。该方法可以由一个装置执行,该装置可以由软件和/或硬件实现。
在本实施例中,目标语料数据的爬取方法包括步骤S1-S6:
S1、接收用户提出的携带初始语料库的目标语料数据的爬取请求,确定所述目标语料数据的爬取请求对应的指定信息抓取规则及目标信息抓取规则;
以下内容以电子装置作为执行主体对本申请方法实施例进行说明,其中,电子装置作为服务器与用户终端建立通讯连接,并接收用户终端发送的爬取请求,根据爬取请求进行相应处理。
在本实施例中,以资讯类网站的网页数据为例,但不仅限于资讯类网站的网页数据。上述爬取请求中包括:初始语料库、目标语料数据类型、爬取路径等。也就是说,用户在提交爬取请求的同时,提交初始语料库及目标语料数据中的目标信息类型,即,需要抓取的内容,然后通过用户终端将该爬取请求发送至电子装置,供电子装置将该爬取请求发送至预设客户端。
初始语料库,指的是预先确定的待爬取的网页URL(Uniform Resource Location,统一资源定位符)列表,例如,是用户在提交爬取请求时一并提供的资讯类网页URL列表。通过初始语料库中的网页URL列表,可以获取各网页的标题页、列表页和内容页等内容。
例如,用户想从携程网上获取游记信息:标题、作者、正文,用户需先提供携程网中游记的URL列表,根据URL列表得到游记内容页,然后从游记的内容页中得到标题、作者和正文信息。
其中,上述预设客户端为爬虫工程师使用的终端,在接收到爬取请求之后,调用预设的爬虫通用框架,并根据爬取请求中需求内容的类别(例如,资讯类),获取该类别的固定参数,爬虫工程师对需要人为调整的参数进行参 数配置,例如,CPU资源分配、爬取的数据的存储路径等,这里不作说明。然后将参数配置保存至预设路径中的配置文件中。其中,配置文件为XML文件。通过预设爬虫通用框架,可减少爬虫工程师的工作量,提高目标语料数据的爬取效率。
具体地,配置文件中还包括规则库,规则库中包括指定信息抓取规则及目标信息抓取规则。可以理解的是,上述抓取规则与爬取请求的具体内容有关,假如用户要抓取的目标信息为标题、作者、正文,那么需要预先确定抓取目标信息的过程中需使用的抓取规则,包括指定信息抓取规则及目标信息抓取规则,其中,指定信息抓取规则包括:标题页抓取规则、列表页抓取规则、内容页抓取规则,目标信息抓取规则包括:标题抓取规则、作者抓取规则、正文抓取规则。
在本实施例中,所有抓取规则通过正则表达式来实现,也就是说,规则库包括:标题页正则表达式、列表页正则表达式、内容页正则表达式、标题正则表达式、作者正则表达式、正文正则表达式。
具体地,所述目标信息抓取规则通过以下步骤获得:
a1、从指定路径中读取目标信息的初始抓取规则;
a2、对指定网页数据的目标信息进行标注,生成目标信息数据集,并确定目标信息数据集与初始抓取规则的映射关系;
a3、利用所述初始抓取规则从所述指定网页数据中抓取实时信息,生成实时信息数据集;
a4、根据所述初始抓取规则与目标信息的映射关系,读取各初始抓取规则对应的目标信息数据集,计算所述实时信息数据集与目标信息数据集的匹配率;及
a5、当匹配率大于或等于预设阈值时,将所述初始抓取规则作为目标信息抓取规则;当匹配率小于预设阈值时,接收对所述初始抓取规则的调整指令,并返回执行步骤a3。
需要说明的是,在确定目标信息抓取规则之前,事先提供了网站模板的正则表达式列表,以供爬虫工程师进行参考,根据网站模板的正则表达式列表,确定目标信息对应的初始正则表达式,即,初始抓取规则,并将目标信息的初始抓取规则保存至指定路径中。对于不同类型的网页,同一目标内容 对应的正则表达式也不一样,因此,需要爬虫工程师根据爬取请求进行调整。
以资讯类网页为例,假如目标信息包括标题、作者、正文,那么初始抓取规则包括:初始标题抓取规则、初始正文抓取规则及初始作者抓取规则。
采集预设数量的网页数据作为指定网页数据。需要说明的是,指定网页数据可以是网页类型与初始语料库中URL的类型相同的网页数据,也可以是初始语料库中的URL列表中预设比例的URL对应的网页数据。当指定数据是初始语料库的中的URL列表中预设比例的URL对应的网页数据时,随机从初始语料库中的URL列表中抽取预设比例(例如,10%)的URL,爬取其对应的网页数据作为指定网页数据。
例如,当目标信息为标题时,从指定网页数据中提取出每个网页数据中的标题,生成目标标题数据集[X1、X2、X3、Xi、…、Xn],其中,Xi表示指定网页数据中某一个网页数据的实际标题。该目标标题数据集[X1、X2、X3、Xi、…、Xn]与初始标题抓取规则相对应。目标信息还可以是指定网页数据的正文、作者,通过提取指定网页数据中的目标正文及目标作者,确定目标正文数据集及目标作者数据集,目标正文数据集与初始正文抓取规则相对应,目标作者数据集与初始作者抓取规则相对应。
利用初始标题抓取规则从指定网页数据中抓取实时标题信息,生成实时标题数据集[Y1、Y2、Y3、Yi、…、Yn],其中,Yi表示指定网页数据中某一个网页数据的实时标题,即利用抽取规则抽取的标题信息,可能是实际标题信息,也可能不是实际标题信息。
作为一种实施方式,步骤a4可以细化为以下步骤:
分别从目标信息数据集及实时信息数据集中读取各指定网页数据的目标信息及实时信息,并进行比对;及
统计目标信息与实时信息相同的指定网页数据的数量,计算实时信息数据集与目标信息数据集的匹配率。
例如,分别获取目标标题数据集及实时标题数据集,依次对目标标题数据集中的标题信息与实时标题数据集中的标题信息进行比对,即,判断是否满足Xi=Yi,若是,则判断第i条网页数据的目标标题信息与实时标题信息相同,否则,判断第i条网页数据的目标标题信息与实时标题信息不同。
作为一种实施方式,匹配率P计算公式为:P=M/T
其中,M为目标信息与实时信息相同的指定网页数据的数量,T为指定网页数据的总数。
通过计算实时标题数据集与目标标题数据集的匹配率,可以了解其对应的初始标题抓取规则的普适度,从一定程度上反映出抓取到的内容的准确性。
匹配率越大,普适度越高,其抓取的内容越准确,反之,匹配率越小,普适度越低,其抓取的内容越不准确。因此,预先设置一个阈值(例如,80%),当匹配率大于或等于80%,判断其对应的初始抓取规则普适性较高,故将该初始抓取规则作为目标抓取规则并保存;当匹配率小于80%时,判断其对应的初始抓取规则普适性较低,基于该初始抓取规则生成提示信息反馈给预设终端,以供爬虫工程师对该初始抓取规则进行调整,并接收爬虫工程师反馈的对初始抓取规则的调整指令,调整指令中包括调整后的初始抓取规则,然后重复执行步骤a3至a5。
同理,所述规则库中的指定信息抓取规则也可以通过上述步骤获取,这里不作累述。
S2、调用所述指定信息抓取规则中的标题页抓取规则、列表页抓取规则及内容页抓取规则,分别抓取出所述初始语料库中的URL列表对应的第一标题页URL列表、第一列表页URL列表及第一内容页URL列表;
具体地,利用标题页正则表达式抓取第一标题页URL列表,利用列表页正则表达式抓取第一列表页URL列表,利用内容页正则表达式抓取第一内容页URL列表。
S3、访问第一标题页URL列表中的标题页,调用所述列表页抓取规则,抓取出所述第一标题页URL列表对应的第二列表页URL列表;
S4、合并所述第一列表页URL列表及所述第二列表页URL列表生成第三列表页URL列表,调用所述内容页抓取规则,抓取出所述第三列表页URL列表对应的第二内容页URL列表;
通过第一标题页URL列表,抓取第一标题页URL列表对应的第二列表页URL列表,并将其与第一列表页URL列表进行合并,得到列表页URL更为全面的第三列表页URL列表。
S5、合并所述第一内容页URL列表及所述第二内容页URL列表生成第三内容页URL列表,抓取所述第三内容页URL列表对应的内容页数据,生 成第一语料数据;
同理,通过访问第三列表页URL列表中的列表页,获取列表页网页源码,并从网页源码中抓取其对应的第二内容页URL列表,并将其与第一内容页URL列表进行和并,得到内同业URL更为全面的第三内容页URL列表。调用爬虫程序爬取通过上述步骤得到的第三内容页URL列表中每一条内容页URL对应的数据,生成第一语料数据。
S6、调用所述目标信息抓取规则,从所述第一语料数据中抓取目标信息,确定目标语料数据,将所述目标语料数据发送给用户。
利用所述标题抓取规则、作者抓取规则、正文抓取规则,分别从所述第一语料数据中的内容页数据中提取出标题、作者和正文的语料,作为目标语料数据,然后将目标语料数据反馈给用户。
在其他实施例中,所述指定信息抓取规则中还包括:目标信息去噪规则,步骤S6还包括:
调用预设目标信息去噪规则,对所述目标信息进行去噪处理,确定目标语料数据。
在本实施例中,目标信息去噪规则包括:标题去噪音规则、作者去噪音规则、正文去噪音规则,即,标题去噪音正则表达式、作者去噪音正则表达式、正文去噪音正则表达式。
利用标题去噪音正则表达式对目标标题信息进行去噪音处理,利用作者去噪音正则表达式对目标作者信息进行去噪音处理,利用正文去噪音正则表达式对目标正文信息进行去噪音处理,得到经过清洗后的语料数据,然后将清洗后的语料数据作为目标语料数据保存至目标语料库中,并将目标语料库反馈给用户。
上述实施例提出的目标语料数据的爬取方法,在接收到目标信息的爬取请求后,首先确定爬取目标语料所需的爬取规则,调用爬取规则,依次爬取第一标题页URL列表、第一列表页URL列表及第一内容页URL列表,然后爬取第一标题页URL列表对应的第二列表页URL列表,生成第三列表页URL列表,爬取第三列表页URL列表对应的第二内容页URL列表,生成第三内容页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、接收用户提出的携带初始语料库的目标语料数据的爬取请求,确定所述目标语料数据的爬取请求对应的指定信息抓取规则及目标信息抓取规则;
以下内容以电子装置1作为执行主体对本申请方法实施例进行说明,其中,电子装置作为服务器与用户终端建立通讯连接,并接收用户终端发送的爬取请求,根据爬取请求进行相应处理。
在本实施例中,以资讯类网站的网页数据为例,但不仅限于资讯类网站的网页数据。上述爬取请求中包括:初始语料库、目标语料数据类型、爬取路径等。也就是说,用户在提交爬取请求的同时,提交初始语料库及目标语料数据中的目标信息类型,即,需要抓取的内容,然后通过用户终端将该爬取请求发送至电子装置,供电子装置将该爬取请求发送至预设客户端。
初始语料库,指的是预先确定的待爬取的网页URL列表,例如,是用户在提交爬取请求时一并提供的资讯类网页URL列表。通过初始语料库中的网页URL列表,可以获取各网页的标题页、列表页和内容页等内容。
例如,用户想从携程网上获取游记信息:标题、作者、正文,用户需先提供携程网中游记的URL列表,根据的URL列表得到游记内容页,然后从游记的内容页中得到标题、作者和正文信息。
其中,上述预设客户端为爬虫工程师使用的终端,在接收到爬取请求之后,调用预设的爬虫通用框架,并根据爬取请求中需求内容的类别(例如,资讯类),获取该类别的固定参数,爬虫工程师对需要人为调整的参数进行参数配置,例如,CPU资源分配、爬取的数据的存储路径等,这里不作说明。然后将参数配置保存至预设路径中的配置文件中。其中,配置文件为XML文件。通过预设爬虫通用框架,可减少爬虫工程师的工作量,提高目标语料数据的爬取效率。
具体地,配置文件中还包括规则库,规则库中包括指定信息抓取规则及目标信息抓取规则。可以理解的是,上述抓取规则与爬取请求的具体内容有关,假如用户要抓取的目标信息为标题、作者、正文,那么需要预先确定抓取目标信息的过程中需使用的抓取规则,包括指定信息抓取规则及目标信息抓取规则,其中,指定信息抓取规则包括:标题页抓取规则、列表页抓取规则、内容页抓取规则,目标信息抓取规则包括:标题抓取规则、作者抓取规则、正文抓取规则。
在本实施例中,所有抓取规则通过正则表达式来实现,也就是说,规则库包括:标题页正则表达式、列表页正则表达式、内容页正则表达式、标题正则表达式、作者正则表达式、正文正则表达式。
具体地,所述目标信息抓取规则通过以下步骤获得:
a1、从指定路径中读取目标信息的初始抓取规则;
a2、对指定网页数据的目标信息进行标注,生成目标信息数据集,并确定目标信息数据集与初始抓取规则的映射关系;
a3、利用所述初始抓取规则从所述指定网页数据中抓取实时信息,生成实时信息数据集;
a4、根据所述初始抓取规则与目标信息的映射关系,读取各初始抓取规则对应的目标信息数据集,计算所述实时信息数据集与目标信息数据集的匹配率;及
a5、当匹配率大于或等于预设阈值时,将所述初始抓取规则作为目标信息抓取规则;当匹配率小于预设阈值时,接收对所述初始抓取规则的调整指令,并返回执行步骤a3。
需要说明的是,在确定目标信息抓取规则之前,事先提供了网站模板的正则表达式列表,以供爬虫工程师进行参考,根据网站模板的正则表达式列表,确定目标信息对应的初始正则表达式,即,初始抓取规则,并将目标信息的初始抓取规则保存至指定路径中。对于不同类型的网页,同一目标内容对应的正则表达式也不一样,因此,需要爬虫工程师根据爬取请求进行调整。
以资讯类网页为例,假如目标信息包括标题、作者、正文,那么初始抓取规则包括:初始标题抓取规则、初始正文抓取规则及初始作者抓取规则。
采集预设数量的网页数据作为指定网页数据。需要说明的是,指定网页 数据可以是网页类型与初始语料库中URL的类型相同的网页数据,也可以是初始语料库中的URL列表中预设比例的URL对应的网页数据。当指定数据是初始语料库的中的URL列表中预设比例的URL对应的网页数据时,随机从初始语料库中的URL列表中抽取预设比例(例如,10%)的URL,爬取其对应的网页数据作为指定网页数据。
例如,当目标信息为标题时,从指定网页数据中提取出每个网页数据中的标题,生成目标标题数据集[X1、X2、X3、Xi、…、Xn],其中,Xi表示指定网页数据中某一个网页数据的实际标题。该目标标题数据集[X1、X2、X3、Xi、…、Xn]与初始标题抓取规则相对应。目标信息还可以是指定网页数据的正文、作者,通过提取指定网页数据中的目标正文及目标作者,确定目标正文数据集及目标作者数据集,目标正文数据集与初始正文抓取规则相对应,目标作者数据集与初始作者抓取规则相对应。
利用初始标题抓取规则从指定网页数据中抓取实时标题信息,生成实时标题数据集[Y1、Y2、Y3、Yi、…、Yn],其中,Yi表示指定网页数据中某一个网页数据的实时标题,即利用抽取规则抽取的标题信息,可能是实际标题信息,也可能不是实际标题信息。
作为一种实施方式,步骤a4可以细化为以下步骤:
分别从目标信息数据集及实时信息数据集中读取各指定网页数据的目标信息及实时信息,并进行比对;及
统计目标信息与实时信息相同的指定网页数据的数量,计算实时信息数据集与目标信息数据集的匹配率。
例如,分别获取目标标题数据集及实时标题数据集,依次对目标标题数据集中的标题信息与实时标题数据集中的标题信息进行比对,即,判断是否满足Xi=Yi,若是,则判断第i条网页数据的目标标题信息与实时标题信息相同,否则,判断第i条网页数据的目标标题信息与实时标题信息不同。
作为一种实施方式,匹配率P计算公式为:P=M/T
其中,M为目标信息与实时信息相同的指定网页数据的数量,T为指定网页数据的总数。
通过计算实时标题数据集与目标标题数据集的匹配率,可以了解其对应的初始标题抓取规则的普适度,从一定程度上反映出抓取到的内容的准确性。
匹配率越大,普适度越高,其抓取的内容越准确,反之,匹配率越小,普适度越低,其抓取的内容越不准确。因此,预先设置一个阈值(例如,80%),当匹配率大于或等于80%,判断其对应的初始抓取规则普适性较高,故将该初始抓取规则作为目标抓取规则并保存;当匹配率小于80%时,判断其对应的初始抓取规则普适性较低,基于该初始抓取规则生成提示信息反馈给预设终端,以供爬虫工程师对该初始抓取规则进行调整,并接收爬虫工程师反馈的对初始抓取规则的调整指令,调整指令中包括调整后的初始抓取规则,然后重复执行步骤a3至a5。
同理,所述规则库中的指定信息抓取规则也可以通过上述步骤获取,这里不作累述。
A2、调用所述指定信息抓取规则中的标题页抓取规则、列表页抓取规则及内容页抓取规则,分别抓取出所述初始语料库中的URL列表对应的第一标题页URL列表、第一列表页URL列表及第一内容页URL列表;
具体地,利用标题页正则表达式抓取第一标题页URL列表,利用列表页正则表达式抓取第一列表页URL列表,利用内容页正则表达式抓取第一内容页URL列表。
A3、访问第一标题页URL列表中的标题页,调用所述列表页抓取规则,抓取出所述第一标题页URL列表对应的第二列表页URL列表;
A4、合并所述第一列表页URL列表及所述第二列表页URL列表生成第三列表页URL列表,调用所述内容页抓取规则,抓取出所述第三列表页URL列表对应的第二内容页URL列表;
通过第一标题页URL列表,抓取第一标题页URL列表对应的第二列表页URL列表,并将其与第一列表页URL列表进行合并,得到列表页URL更为全面的第三列表页URL列表。
A5、合并所述第一内容页URL列表及所述第二内容页URL列表生成第三内容页URL列表,抓取所述第三内容页URL列表对应的内容页数据,生成第一语料数据;
同理,通过访问第三列表页URL列表中的列表页,获取列表页网页源码,并从网页源码中抓取其对应的第二内容页URL列表,并将其与第一内容页URL列表进行和并,得到内同业URL更为全面的第三内容页URL列表。调 用爬虫程序爬取通过上述步骤得到的第三内容页URL列表中每一条内容页URL对应的数据,生成第一语料数据。
A6、调用所述目标信息抓取规则,从所述第一语料数据中抓取目标信息,确定目标语料数据,将所述目标语料数据发送给用户。
利用所述标题抓取规则、作者抓取规则、正文抓取规则,分别从所述第一语料数据中的内容页数据中提取出标题、作者和正文的语料,作为目标语料数据,然后将目标语料数据反馈给用户。
在其他实施例中,所述指定信息抓取规则中还包括:目标信息去噪规则,步骤A6还包括:
调用预设目标信息去噪规则,对所述目标信息进行去噪处理,确定目标语料数据。
在本实施例中,目标信息去噪规则包括:标题去噪音规则、作者去噪音规则、正文去噪音规则,即,标题去噪音正则表达式、作者去噪音正则表达式、正文去噪音正则表达式。
利用标题去噪音正则表达式对目标标题信息进行去噪音处理,利用作者去噪音正则表达式对目标作者信息进行去噪音处理,利用正文去噪音正则表达式对目标正文信息进行去噪音处理,得到经过清洗后的语料数据,然后将清洗后的语料数据作为目标语料数据保存至目标语料库中,并将目标语料库反馈给用户。
上述实施例提出的电子装置1,在接收到目标信息的爬取请求后,首先确定爬取目标语料所需的爬取规则,调用爬取规则,依次爬取第一标题页URL列表、第一列表页URL列表及第一内容页URL列表,然后爬取第一标题页URL列表对应的第二列表页URL列表,生成第三列表页URL列表,爬取第三列表页URL列表对应的第二内容页URL列表,生成第三内容页URL列表,以获取内容页数据,最后利用目标信息爬取规则爬取出目标信息,通过确定普适度高的爬取规则,提高目标语料数据的爬取效率,通过获取更全面的内容页数据,使爬取的目标语料数据更准确。
可选地,在其他的实施例中,目标语料数据的爬取程序10还可以被分割为一个或者多个模块,一个或者多个模块被存储于存储器11中,并由一个或 多个处理器(本实施例为处理器12)所执行,以完成本申请,本申请所称的模块是指能够完成特定功能的一系列计算机程序指令段。例如,参照图3所示,为图2中目标语料数据的爬取程序10的模块示意图,该实施例中,目标语料数据的爬取程序10可以被分割为接收模块110、第一抓取模块120、第二抓取模块130、第三抓取模块140、第四抓取模块150及发送模块160,所述模块110-160所实现的功能或操作步骤均与上文类似,此处不再详述,示例性地,例如其中:
接收模块110,用于接收用户提出的携带初始语料库的目标语料数据的爬取请求,确定所述目标语料数据的爬取请求对应的指定信息抓取规则及目标信息抓取规则;
第一抓取模块120,用于读取所述指定信息抓取规则中的标题页抓取规则、列表页抓取规则及内容页抓取规则,分别抓取出所述初始语料库中的URL(Uniform Resource Location,统一资源定位符)列表对应的第一标题页URL列表、第一列表页URL列表及第一内容页URL列表;
第二抓取模块130,用于访问第一标题页URL列表中的标题页,调用所述列表页抓取规则,抓取出所述第一标题页URL列表对应的第二列表页URL列表;
第三抓取模块140,用于合并所述第一列表页URL列表及所述第二列表页URL列表生成第三列表页URL列表,调用所述内容页抓取规则,抓取出所述第三列表页URL列表对应的第二内容页URL列表;
第四抓取模块150,用于合并所述第一内容页URL列表及所述第二内容页URL列表生成第三内容页URL列表,抓取所述第三内容页URL列表对应的内容页数据,生成第一语料数据;及
发送模块160,用于调用所述目标信息抓取规则,从所述第一语料数据中抓取目标信息,确定目标语料数据,将所述目标语料数据发送给用户。
此外,本申请实施例还提出一种计算机可读存储介质,所述计算机可读存储介质中包括目标语料数据的爬取程序10,所述目标语料数据的爬取程序10被处理器执行时实现如下操作:
A1、接收用户提出的携带初始语料库的目标语料数据的爬取请求,确定 所述目标语料数据的爬取请求对应的指定信息抓取规则及目标信息抓取规则;
A2、读取所述指定信息抓取规则中的标题页抓取规则、列表页抓取规则及内容页抓取规则,分别抓取出所述初始语料库中的URL列表对应的第一标题页URL列表、第一列表页URL列表及第一内容页URL列表;
A3、访问第一标题页URL列表中的标题页,调用所述列表页抓取规则,抓取出所述第一标题页URL列表对应的第二列表页URL列表;
A4、合并所述第一列表页URL列表及所述第二列表页URL列表生成第三列表页URL列表,调用所述内容页抓取规则,抓取出所述第三列表页URL列表对应的第二内容页URL列表;
A5、合并所述第一内容页URL列表及所述第二内容页URL列表生成第三内容页URL列表,抓取所述第三内容页URL列表对应的内容页数据,生成第一语料数据;及
A6、调用所述目标信息抓取规则,从所述第一语料数据中抓取目标信息,确定目标语料数据,将所述目标语料数据发送给用户。
本申请之计算机可读存储介质的具体实施方式与上述目标语料数据的爬取方法的具体实施方式大致相同,在此不再赘述。
上述本申请实施例序号仅仅为了描述,不代表实施例的优劣。
需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、装置、物品或者方法不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、装置、物品或者方法所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、装置、物品或者方法中还存在另外的相同要素。
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在如上所述的一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算 机,服务器,或者网络设备等)执行本申请各个实施例所述的方法。
以上仅为本申请的优选实施例,并非因此限制本申请的专利范围,凡是利用本申请说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其它相关的技术领域,均同理包括在本申请的专利保护范围内。
Claims (20)
- 一种目标语料数据的爬取方法,应用于电子装置,其特征在于,所述方法包括:S1、接收用户提出的携带初始语料库的目标语料数据的爬取请求,确定所述目标语料数据的爬取请求对应的指定信息抓取规则及目标信息抓取规则;S2、读取所述指定信息抓取规则中的标题页抓取规则、列表页抓取规则及内容页抓取规则,分别抓取出所述初始语料库中的URL(Uniform Resource Location,统一资源定位符)列表对应的第一标题页URL列表、第一列表页URL列表及第一内容页URL列表;S3、访问第一标题页URL列表中的标题页,调用所述列表页抓取规则,抓取出所述第一标题页URL列表对应的第二列表页URL列表;S4、合并所述第一列表页URL列表及所述第二列表页URL列表生成第三列表页URL列表,调用所述内容页抓取规则,抓取出所述第三列表页URL列表对应的第二内容页URL列表;S5、合并所述第一内容页URL列表及所述第二内容页URL列表生成第三内容页URL列表,抓取所述第三内容页URL列表对应的内容页数据,生成第一语料数据;及S6、调用所述目标信息抓取规则,从所述第一语料数据中抓取目标信息,确定目标语料数据,将所述目标语料数据发送给用户。
- 根据权利要求1所述的目标语料数据的爬取方法,其特征在于,所述指定信息抓取规则中还包括:目标信息去噪规则,所述步骤S6还包括:调用预设目标信息去噪规则,对所述目标信息进行去噪处理,确定目标语料数据。
- 根据权利要求1所述的目标语料数据的爬取方法,其特征在于,所述目标信息抓取规则通过以下步骤确定:a1、从指定路径中读取目标信息的初始抓取规则;a2、对指定网页数据的目标信息进行标注,生成目标信息数据集,并确定目标信息数据集与初始抓取规则的映射关系;a3、利用所述初始抓取规则从所述指定网页数据中抓取实时信息,生成实时信息数据集;a4、根据所述初始抓取规则与目标信息的映射关系,读取各初始抓取规则对应的目标信息数据集,计算所述实时信息数据集与目标信息数据集的匹配率;及a5、当匹配率大于或等于预设阈值时,将所述初始抓取规则作为目标信息抓取规则;当匹配率小于预设阈值时,接收对所述初始抓取规则的调整指令,并返回执行步骤a3。
- 根据权利要求3所述的目标语料数据的爬取方法,其特征在于,所述步骤a4包括:分别从目标信息数据集及实时信息数据集中读取各指定网页数据的目标信息及实时信息,并进行比对;及统计目标信息与实时信息相同的指定网页数据的数量,计算实时信息数据集与目标信息数据集的匹配率。
- 根据权利要求4所述的目标语料数据的爬取方法,其特征在于,所述匹配率的计算公式为:P=M/T其中,P为实时信息数据集与目标信息数据集的匹配率,M为目标信息与实时信息相同的指定网页数据的数量,T为指定网页数据的总数。
- 根据权利要求5中所述的目标语料数据的爬取方法,其特征在于,所述指定信息抓取规则中还包括:目标信息去噪规则,所述步骤S6还包括:调用预设目标信息去噪规则,对所述目标信息进行去噪处理,确定目标语料数据。
- 根据权利要求6所述的目标语料数据的爬取方法,其特征在于,所述指定信息抓取规则及目标信息抓取规则均通过正则表达式来实现。
- 一种电子装置,其特征在于,该装置包括:存储器、处理器,所述存储器上存储有可在所述处理器上运行的目标语料数据的爬取程序,所述目标语料数据的爬取程序被所述处理器执行时,可实现如下步骤:A1、接收用户提出的携带初始语料库的目标语料数据的爬取请求,确定所述目标语料数据的爬取请求对应的指定信息抓取规则及目标信息抓取规则;A2、读取所述指定信息抓取规则中的标题页抓取规则、列表页抓取规则及内容页抓取规则,分别抓取出所述初始语料库中的URL列表对应的第一标题页URL列表、第一列表页URL列表及第一内容页URL列表;A3、访问第一标题页URL列表中的标题页,调用所述列表页抓取规则,抓取出所述第一标题页URL列表对应的第二列表页URL列表;A4、合并所述第一列表页URL列表及所述第二列表页URL列表生成第三列表页URL列表,调用所述内容页抓取规则,抓取出所述第三列表页URL列表对应的第二内容页URL列表;A5、合并所述第一内容页URL列表及所述第二内容页URL列表生成第三内容页URL列表,抓取所述第三内容页URL列表对应的内容页数据,生成第一语料数据;及A6、调用所述目标信息抓取规则,从所述第一语料数据中抓取目标信息,确定目标语料数据,将所述目标语料数据发送给用户。
- 根据权利要求8所述的电子装置,其特征在于,所述指定信息抓取规则中还包括:目标信息去噪规则,所述步骤A6还包括:调用预设目标信息去噪规则,对所述目标信息进行去噪处理,确定目标语料数据。
- 根据权利要求8所述的电子装置,其特征在于,所述目标信息抓取规则通过以下步骤确定:a1、从指定路径中读取目标信息的初始抓取规则;a2、对指定网页数据的目标信息进行标注,生成目标信息数据集,并确定目标信息数据集与初始抓取规则的映射关系;a3、利用所述初始抓取规则从所述指定网页数据中抓取实时信息,生成实时信息数据集;a4、根据所述初始抓取规则与目标信息的映射关系,读取各初始抓取规则对应的目标信息数据集,计算所述实时信息数据集与目标信息数据集的匹配率;及a5、当匹配率大于或等于预设阈值时,将所述初始抓取规则作为目标信息抓取规则;当匹配率小于预设阈值时,接收对所述初始抓取规则的调整指令,并返回执行步骤a3。
- 根据权利要求10所述的电子装置,其特征在于,所述步骤a4包括:分别从目标信息数据集及实时信息数据集中读取各指定网页数据的目标信息及实时信息,并进行比对;及统计目标信息与实时信息相同的指定网页数据的数量,计算实时信息数据集与目标信息数据集的匹配率。
- 根据权利要求11所述的电子装置,其特征在于,所述匹配率的计算公式为:P=M/T其中,P为实时信息数据集与目标信息数据集的匹配率,M为目标信息与实时信息相同的指定网页数据的数量,T为指定网页数据的总数。
- 根据权利要求12所述的电子装置,其特征在于,所述指定信息抓取规则中还包括:目标信息去噪规则,所述步骤A6还包括:调用预设目标信息去噪规则,对所述目标信息进行去噪处理,确定目标语料数据。
- 根据权利要求13所述的电子装置,其特征在于,所述指定信息抓取规则及目标信息抓取规则均通过正则表达式来实现。
- 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质中包括目标语料数据的爬取程序,所述目标语料数据的爬取程序被处理器执行时,可实现如下步骤:A1、接收用户提出的携带初始语料库的目标语料数据的爬取请求,确定所述目标语料数据的爬取请求对应的指定信息抓取规则及目标信息抓取规则;A2、读取所述指定信息抓取规则中的标题页抓取规则、列表页抓取规则及内容页抓取规则,分别抓取出所述初始语料库中的URL列表对应的第一标题页URL列表、第一列表页URL列表及第一内容页URL列表;A3、访问第一标题页URL列表中的标题页,调用所述列表页抓取规则,抓取出所述第一标题页URL列表对应的第二列表页URL列表;A4、合并所述第一列表页URL列表及所述第二列表页URL列表生成第三列表页URL列表,调用所述内容页抓取规则,抓取出所述第三列表页URL列表对应的第二内容页URL列表;A5、合并所述第一内容页URL列表及所述第二内容页URL列表生成第三内容页URL列表,抓取所述第三内容页URL列表对应的内容页数据,生成第一语料数据;及A6、调用所述目标信息抓取规则,从所述第一语料数据中抓取目标信息,确定目标语料数据,将所述目标语料数据发送给用户。
- 根据权利要求15所述的计算机可读存储介质,其特征在于,所述目标信息抓取规则通过以下步骤确定:a1、从指定路径中读取目标信息的初始抓取规则;a2、对指定网页数据的目标信息进行标注,生成目标信息数据集,并确定目标信息数据集与初始抓取规则的映射关系;a3、利用所述初始抓取规则从所述指定网页数据中抓取实时信息,生成实时信息数据集;a4、根据所述初始抓取规则与目标信息的映射关系,读取各初始抓取规则对应的目标信息数据集,计算所述实时信息数据集与目标信息数据集的匹配率;及a5、当匹配率大于或等于预设阈值时,将所述初始抓取规则作为目标信息抓取规则;当匹配率小于预设阈值时,接收对所述初始抓取规则的调整指令,并返回执行步骤a3。
- 根据权利要求16所述的计算机可读存储介质,其特征在于,所述步骤a4包括:分别从目标信息数据集及实时信息数据集中读取各指定网页数据的目标信息及实时信息,并进行比对;及统计目标信息与实时信息相同的指定网页数据的数量,计算实时信息数据集与目标信息数据集的匹配率。
- 根据权利要求17所述的计算机可读存储介质,其特征在于,所述匹配率的计算公式为:P=M/T其中,P为实时信息数据集与目标信息数据集的匹配率,M为目标信息与实时信息相同的指定网页数据的数量,T为指定网页数据的总数。
- 根据权利要求18所述的计算机可读存储介质,其特征在于,所述指定信息抓取规则中还包括:目标信息去噪规则,所述步骤A6还包括:调用预设目标信息去噪规则,对所述目标信息进行去噪处理,确定目标语料数据。
- 根据权利要求19所述的计算机可读存储介质,其特征在于,所述指定信息抓取规则及目标信息抓取规则均通过正则表达式来实现。
Applications Claiming Priority (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201810876287.2A CN109190062B (zh) | 2018-08-03 | 2018-08-03 | 目标语料数据的爬取方法、装置及存储介质 |
| CN201810876287.2 | 2018-08-03 |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| WO2020024403A1 true WO2020024403A1 (zh) | 2020-02-06 |
Family
ID=64920024
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| PCT/CN2018/107489 Ceased WO2020024403A1 (zh) | 2018-08-03 | 2018-09-26 | 目标语料数据的爬取方法、装置及存储介质 |
Country Status (2)
| Country | Link |
|---|---|
| CN (1) | CN109190062B (zh) |
| WO (1) | WO2020024403A1 (zh) |
Cited By (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN116361362A (zh) * | 2023-05-30 | 2023-06-30 | 江西顶易科技发展有限公司 | 一种基于网页内容识别的用户信息挖掘方法与系统 |
| WO2024165557A1 (fr) | 2023-02-08 | 2024-08-15 | Institut National De Recherche Pour L'agriculture L'alimentation Et L'environnement | Fucanases et leur utilisation pour hydrolyser des polysaccharides |
Families Citing this family (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN109918486B (zh) * | 2019-01-24 | 2024-03-19 | 平安科技(深圳)有限公司 | 智能客服的语料构建方法、装置、计算机设备及存储介质 |
| CN112818212B (zh) * | 2020-04-23 | 2023-10-13 | 腾讯科技(深圳)有限公司 | 语料数据采集方法、装置、计算机设备和存储介质 |
| CN112052320B (zh) * | 2020-09-01 | 2023-09-29 | 腾讯科技(深圳)有限公司 | 一种信息处理方法、装置及计算机可读存储介质 |
Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN103020043A (zh) * | 2012-11-16 | 2013-04-03 | 哈尔滨工业大学 | 一种面向web双语平行语料资源的分布式采集系统 |
| CN103793509A (zh) * | 2014-01-27 | 2014-05-14 | 北京奇虎科技有限公司 | 组图抓取方法与装置 |
| CN107885777A (zh) * | 2017-10-11 | 2018-04-06 | 北京智慧星光信息技术有限公司 | 一种基于协作式爬虫的抓取网页数据的控制方法及系统 |
Family Cites Families (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| KR20120042529A (ko) * | 2010-10-25 | 2012-05-03 | 삼성전자주식회사 | 웹 페이지 크롤링 방법 및 장치 |
| CN107704515A (zh) * | 2017-09-01 | 2018-02-16 | 安徽简道科技有限公司 | 基于互联网数据抓取系统的数据抓取方法 |
| CN108334585A (zh) * | 2018-01-29 | 2018-07-27 | 湖北省楚天云有限公司 | 一种网页爬虫方法、装置以及电子设备 |
-
2018
- 2018-08-03 CN CN201810876287.2A patent/CN109190062B/zh active Active
- 2018-09-26 WO PCT/CN2018/107489 patent/WO2020024403A1/zh not_active Ceased
Patent Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN103020043A (zh) * | 2012-11-16 | 2013-04-03 | 哈尔滨工业大学 | 一种面向web双语平行语料资源的分布式采集系统 |
| CN103793509A (zh) * | 2014-01-27 | 2014-05-14 | 北京奇虎科技有限公司 | 组图抓取方法与装置 |
| CN107885777A (zh) * | 2017-10-11 | 2018-04-06 | 北京智慧星光信息技术有限公司 | 一种基于协作式爬虫的抓取网页数据的控制方法及系统 |
Cited By (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| WO2024165557A1 (fr) | 2023-02-08 | 2024-08-15 | Institut National De Recherche Pour L'agriculture L'alimentation Et L'environnement | Fucanases et leur utilisation pour hydrolyser des polysaccharides |
| CN116361362A (zh) * | 2023-05-30 | 2023-06-30 | 江西顶易科技发展有限公司 | 一种基于网页内容识别的用户信息挖掘方法与系统 |
| CN116361362B (zh) * | 2023-05-30 | 2023-08-11 | 江西顶易科技发展有限公司 | 一种基于网页内容识别的用户信息挖掘方法与系统 |
Also Published As
| Publication number | Publication date |
|---|---|
| CN109190062B (zh) | 2023-04-07 |
| CN109190062A (zh) | 2019-01-11 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| WO2020024403A1 (zh) | 目标语料数据的爬取方法、装置及存储介质 | |
| CA2684822C (en) | Data transformation based on a technical design document | |
| US9934206B2 (en) | Method and apparatus for extracting web page content | |
| WO2019041521A1 (zh) | 用户关键词提取装置、方法及计算机可读存储介质 | |
| US20160026616A1 (en) | Presenting dataset of spreadsheet in form based view | |
| CN104133870B (zh) | 一种网页相似度计算方法及装置 | |
| US11620444B2 (en) | Providing action associated with event detected within communication | |
| TWI584149B (zh) | Web page access request response method and device | |
| WO2023155712A1 (zh) | 页面生成方法、显示方法、装置、电子设备和存储介质 | |
| WO2020015170A1 (zh) | 接口调用方法、装置及计算机可读存储介质 | |
| WO2015010566A1 (zh) | 综合信息精准搜索方法 | |
| TW201800962A (zh) | 網頁文件發送方法、網頁渲染方法及裝置、網頁渲染系統 | |
| EP3175375A1 (en) | Image based search to identify objects in documents | |
| CN111158777B (zh) | 组件调用方法、装置及计算机可读存储介质 | |
| TWI683225B (zh) | 腳本生成方法與裝置 | |
| US8290928B1 (en) | Generating sitemap where last modified time is not available to a network crawler | |
| WO2019205374A1 (zh) | 模型的在线训练方法、服务器及存储介质 | |
| US9465814B2 (en) | Annotating search results with images | |
| CN110223044A (zh) | 一种邮件推送方法、系统及电子设备和存储介质 | |
| CN107430614A (zh) | 到对应资源的应用局部深度链接 | |
| WO2017107708A1 (zh) | 自适应用户代理的统一资源定位符前缀挖掘方法和装置 | |
| CN112051952A (zh) | 图片动态浏览方法、装置、电子设备及可读存储介质 | |
| US9875316B2 (en) | Identifying user selection using coordinates and snapshots of webpages | |
| CN102663063B (zh) | 基于xslt的多种用户平台通用信息展示系统及方法 | |
| CN114489886A (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: 18928429 Country of ref document: EP Kind code of ref document: A1 |
|
| NENP | Non-entry into the national phase |
Ref country code: DE |
|
| 32PN | Ep: public notification in the ep bulletin as address of the adressee cannot be established |
Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205 DATED 25.03.2021.) |
|
| 122 | Ep: pct application non-entry in european phase |
Ref document number: 18928429 Country of ref document: EP Kind code of ref document: A1 |