WO2014000571A1 - 一种网页中非正文文本的识别系统及方法 - Google Patents

一种网页中非正文文本的识别系统及方法 Download PDF

Info

Publication number
WO2014000571A1
WO2014000571A1 PCT/CN2013/077102 CN2013077102W WO2014000571A1 WO 2014000571 A1 WO2014000571 A1 WO 2014000571A1 CN 2013077102 W CN2013077102 W CN 2013077102W WO 2014000571 A1 WO2014000571 A1 WO 2014000571A1
Authority
WO
WIPO (PCT)
Prior art keywords
text
unit
node
dom tree
text segment
Prior art date
Application number
PCT/CN2013/077102
Other languages
English (en)
French (fr)
Inventor
王志刚
Original Assignee
北京奇虎科技有限公司
奇智软件(北京)有限公司
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 北京奇虎科技有限公司, 奇智软件(北京)有限公司 filed Critical 北京奇虎科技有限公司
Priority to US14/411,013 priority Critical patent/US10042827B2/en
Publication of WO2014000571A1 publication Critical patent/WO2014000571A1/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/205Parsing
    • G06F40/216Parsing using statistical methods
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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/958Organisation or management of web site content, e.g. publishing, maintaining pages or automatic linking
    • G06F16/986Document structures and storage, e.g. HTML extensions
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/12Use of codes for handling textual entities
    • G06F40/14Tree-structured documents
    • G06F40/143Markup, e.g. Standard Generalized Markup Language [SGML] or Document Type Definition [DTD]

Definitions

  • the present invention relates to the field of text extraction technology, and in particular, to a system and method for identifying non-text text in a webpage. Background technique
  • Text extraction plays an increasingly important role in search engines, mobile reading and other fields.
  • the commonly used techniques for text extraction are rule-based, DOM (Document Object Model) based trees, marker-based windows, based on maximum text blocks, and so on. These methods need to exclude non-textual texts on the website, such as advertisements, website announcements, etc.
  • Figure la it is a schematic diagram of the code segment of a website statement.
  • Figure lb is the actual display effect of the code segment in the web page. This kind of website statement is very common in web pages, and it is necessary for users to read less. Exclude during body extraction. However, how to effectively identify these non-textual texts is a problem.
  • the method of spam keyword density is mainly used for non-text text recognition.
  • a dictionary of junk keywords is required, and the dictionary is continuously updated.
  • new junk keywords can only be added after the problem is discovered. Therefore, this method has a serious lag for the solution of the problem, and this lag is more prominent when faced with massive data of the entire Internet. Summary of the invention
  • the present invention has been made in order to provide an identification system and method for non-text text in a web page that overcomes the above problems or at least partially solves or alleviates the above problems.
  • an identification system for non-text text in a webpage comprising: a web crawler, a DOM tree construction unit, a DOM tree analysis unit, a text statistics unit, and a text recognition unit;
  • the webpage crawler is adapted to capture data of all webpages of the target website;
  • the DOM tree building unit is adapted to construct a DOM tree corresponding to each webpage of the target website; the segment; the text statistical unit, suitable for statistical calculation The number of occurrences of the unit text segment in all the web pages of the target website;
  • the text recognition unit is adapted to identify the unit text segment as non-text text when the number of occurrences is greater than a predetermined threshold.
  • a method for identifying non-text text in a webpage is provided, the method comprising the steps of:
  • D counting the number of occurrences of the unit text segment in all web pages of the target website; E: determining whether the unit text segment is non-text text according to the number of occurrences.
  • the parser corresponding to the webpage language is used to construct a DOM tree corresponding to each webpage of the target website.
  • a computer program comprising computer readable code causing the server to perform any of claims 9-16 when run on a server The method for identifying non-text text in the webpage.
  • a computer readable medium storing the computer program according to claim 17 is provided.
  • the DOM tree is used to obtain a unit text segment of each webpage, and then the number of occurrences of the unit text segment in the target website is counted, and the number of occurrences thereof is counted.
  • the non-text text on the website is recognized, which overcomes the lag problem of the existing method for non-text text recognition, and has high recognition accuracy, and has wide application prospects in the search engine.
  • Figure 1 a is a schematic diagram of the code segment of a website statement
  • Figure lb is a view showing the actual display effect of the code segment in the webpage in the webpage;
  • 2 is a block diagram of a module for identifying a non-text text in a webpage according to an embodiment of the present invention;
  • FIG. 3 is a block diagram of an internal module of the DOM tree analyzing unit;
  • FIG. 5 is a flowchart of a method for identifying a non-text text in a webpage according to an embodiment of the present invention
  • FIG. 6 is a schematic diagram of a DOM tree corresponding to an HTML webpage
  • Figure 7 is a flow chart of the step C
  • Figure 8 is a flow chart of the step D
  • Figure 9 is a schematic diagram of the statistical principle of the unit text segment
  • Figure 10 schematically shows a block diagram of a server for performing the method according to the invention
  • Fig. 11 schematically shows a memory unit for holding or carrying program code implementing the method according to the invention.
  • FIG. 2 is a block diagram of a system for identifying a non-text text in a webpage according to an embodiment of the present invention.
  • the system includes: a webpage crawler 100, a DOM tree building unit 200, and a DOM tree analyzing unit 300. , text statistics unit 400 and text recognition unit 500.
  • the web crawler 100 is adapted to crawl data of all web pages of a target website, which may generally employ web spiders, web crawlers, search robots or web crawl scripts.
  • the DOM tree building unit 200 is adapted to construct a DOM tree corresponding to each webpage of the target website.
  • the DOM tree building unit uses a parser corresponding to the webpage language, and for the HTML webpage, an HTML parser is used.
  • the DOM tree analyzing unit 300 is adapted to find a unit text segment in the webpage according to the DOM tree.
  • the DOM tree analysis unit 300 includes: a node access module 301 and a text segment division module 302.
  • the node accessing module 301 is adapted to start from the root node of the DOM tree, sequentially access the nodes in the DOM tree, and send the accessed current node to the text segment dividing module 302; Whether there is a node in the DOM tree that needs to be accessed, and if so, the corresponding node is sent to the text segment dividing module 302 as a new current node.
  • the node access module 301 can be a breadth-first algorithm, a depth-first algorithm, or Other search algorithms access nodes in the DOM tree. Since the DOM tree analyzing unit 300 determines that the text segment corresponding to the current node is a unit text segment, the access to the descendant node of the current node is stopped. Therefore, the node access module 301 is preferably adapted to the breadth-first algorithm.
  • the breadth-first algorithm also called the breadth-first search, or the horizontal-first search, is an algorithm that traverses the nodes of the tree along the width of the tree from the upper node to the lower layer starting from the root node.
  • the text segment dividing module 302 is adapted to determine whether the text segment corresponding to the current node satisfies the condition of the unit text segment, and when the condition is met, the text segment corresponding to the current node is used as a unit text segment, and the node is notified
  • the access module 301 stops accessing the descendant nodes of the current node. Wherein, when the longest path of the current node to its descendant node is less than or equal to a predetermined length, and the descendant node of the current node does not include a complex node, the text segment corresponding to the current node is considered to satisfy the condition of the unit text segment.
  • the complex node includes: a node corresponding to the label table, tr, td, ul, ol, frame, select, input, marquee, and/or map.
  • the text statistics unit 400 is adapted to count the number of occurrences of the unit text segment in all web pages of the target website.
  • the text statistic unit 400 further includes: a hash operation module 401 and a statistic module 402.
  • the hash operation module 401 is adapted to perform a hash operation on the unit text segment to obtain a result key value.
  • the statistic module 402 is adapted to count the number of occurrences of the unit text segment in all webpages of the target website according to the result key value.
  • the text recognition unit 500 is adapted to determine whether the number of occurrences is greater than a predetermined threshold, and if so, identify the unit text segment as a non-text text; otherwise, identify the unit text segment as a body text.
  • FIG. 5 is a flowchart of a method for identifying non-text text in a webpage according to an embodiment of the present invention. As shown in FIG. 5, corresponding to the system, the method includes the following steps:
  • the web crawler can generally be a web spider, a web crawler, a search robot, or a web crawl script.
  • the webpage can use HTML (Hypertext Markup Language), XML (extensible markup language, extensible markup "i" language), XHTML (extensible Hypertext Markup Language), markup language, etc.
  • HTML Hypertext Markup Language
  • XML extensible markup language, extensible markup "i" language
  • XHTML extensible Hypertext Markup Language
  • markup language etc.
  • HTML Hypertext Markup Language
  • All pages here include The main web page and the sub web page of the target website.
  • FIG. B Build the DOM tree for each page of the target website.
  • the DOM tree corresponding to each webpage of the target website is constructed by using an HTML parser, and those skilled in the art can easily think that when the webpage uses other markup languages, the corresponding parser can be used, for example, The XML parser builds the DOM tree corresponding to the XML page.
  • Figure 6 is a schematic diagram of a DOM tree corresponding to an HTML web page. As shown in Figure 6, the nodes in the DOM tree correspond to labels or text in the HTML code.
  • FIG. 7 is a flowchart of the step C. As shown in FIG. 7, the step C specifically includes the following steps:
  • C 1 From the root node of the DOM tree, access nodes in the DOM tree in turn.
  • the step C2 specifically includes the following steps:
  • step C21 determining whether the current node meets the following conditions: the longest path of the current node to its descendant node is less than or equal to a predetermined length, and the descendant node of the current node does not include a complex node; if yes, step C22; otherwise, Go to step C3.
  • the meaning of this step is that when the current node is satisfied at the same time, the longest path of the current node to its descendant node is less than or equal to a predetermined length, and the descendant node of the current node does not include a complex node, the current
  • the text segment corresponding to the node is used as the unit text segment.
  • the distance between the left div node and its farthest descendant node in FIG. 6 is 3, which is smaller than the predetermined distance 4, and the descendant node does not include the complex node, and therefore, the left side in FIG.
  • the text segment corresponding to the div node is recognized as a unit text segment. It should be noted that the identification of the unit text segment is independent of the label name of the current node.
  • the descendant node includes each descendant node of the current node, that is, all nodes on the branch where the current node is located and located below the current node.
  • the setting for the predetermined length and the range of nodes included in the complex node may be adjusted as appropriate according to actual usage.
  • the predetermined length may be set to 3 or 4 or 5.
  • the predetermined length is preferably 4. Still taking the DOM tree in Figure 6 as an example, for the div node on the left side of Figure 6, when it acts as When the current node is located, its corresponding branch is div->p->a->text2, and the distance of the div node from its farthest descendant node text2 is 3, which is less than the predetermined length 4.
  • the complex node includes: a node corresponding to the labels table, tr, td, ul, ol, frame, select, input, marquee, and/or map.
  • step C3 determining whether there is a node in the DOM tree that needs to be accessed, and if yes, executing the corresponding node as a new current node, performing step C2; otherwise, performing step D.
  • the nodes in the DOM tree may be accessed by using a breadth-first algorithm, a depth-first algorithm or other search algorithms.
  • a breadth-first algorithm preferably used in the step C1.
  • the step C3 when the nodes in the DOM tree are sequentially accessed according to the breadth-first algorithm, the step C3 specifically includes the following steps:
  • the peer node refers to a node that is in the same layer as the current node, and may be a sibling node of the current node, or may be a non-brother node of the current node (such as the text2 node and text3 in FIG. 6).
  • a node is a peer node but not a sibling node.
  • step C32 Determine whether there is a lower node of the current node that needs to be accessed in the DOM tree, and if yes, execute the lower node as a new current node, and perform step C2; otherwise, execute step D. It should be noted that when the text segment corresponding to the current node is identified as a unit text segment, the descendant node of the current node need not be accessed any more.
  • FIG. 8 is a flowchart of the step D. As shown in FIG. 8, the step D specifically includes the following steps:
  • D1 Hashing the unit text segment to obtain a result key value.
  • the unit text segment is hashed by the MD5 (Message Digest Algorithm 5) algorithm.
  • MD5 Message Digest Algorithm 5
  • a key-value table with the result key value as a key and the occurrence frequency as a value is established, and then each of the key-value tables is determined according to the key-value table. Whether the value corresponding to the key value is greater than the predetermined threshold to identify whether the unit text segment corresponding to each key value is a non-text text.
  • D2 Count the number of occurrences of the unit text segment in all webpages of the target website according to the result key value.
  • step E determining, according to the number of occurrences, whether the unit text segment is a non-text text.
  • the step E specifically includes the steps of: determining whether the number of occurrences is greater than a predetermined threshold, and if so, identifying the unit text segment as a non-text text; otherwise, identifying the unit text segment as a body text.
  • FIG. 9 is a schematic diagram of the statistical principle of the unit text segment. As shown in FIG. 9, the statistical range of the number of occurrences of each of the unit text segments is all the web pages of the target website.
  • the predetermined threshold may be adjusted according to actual usage. For example, the predetermined threshold may preferably be 100, or 90, 150, and the like.
  • the system and method for identifying non-text text in a webpage uses a DOM tree to obtain a unit text segment of each webpage, and then counts the number of occurrences of the unit text segment in the target website, and displays the number of occurrences thereof.
  • the non-text text on the website is recognized, which overcomes the lag problem of the existing method for non-text text recognition, and has high recognition accuracy, and has wide application prospects in the search engine.
  • the various component embodiments of the present invention may be implemented in hardware, or in a software module running on one or more processors, or in a combination thereof. Those skilled in the art will appreciate that some or all of the functionality of the microprocessor or all components of the digital signal processor (DSP) may be used in practice.
  • the invention can also be implemented as a device or device program (e.g., a computer program and a computer program product) for performing some or all of the methods described herein.
  • a program implementing the present invention may be stored on a computer readable medium or may have the form of one or more signals. Such signals may be downloaded from the Internet website, or provided on a carrier signal, or in any other form.
  • FIG. 10 illustrates a server, such as an application server, that can implement a method of identifying non-text text in a web page in accordance with the present invention.
  • the server conventionally includes a processor 1010 and a computer program product or computer readable medium in the form of a memory 1020.
  • the memory 1020 may be an electronic memory such as a flash memory, an EEPROM (Electrically Erasable Programmable Read Only Memory), an EPROM, a hard disk, or a ROM.
  • the memory 1020 has a memory space 1030 for executing program code 1031 of any of the above method steps.
  • storage space 1030 for program code may include various program code 1031 for implementing various steps in the above methods, respectively.
  • the program code can be read from or written to one or more computer program products. These computer programs produce The product includes a program code carrier such as a hard disk, a compact disk (CD), a memory card, or a floppy disk. Such a computer program product is typically a portable or fixed storage unit as described with reference to FIG.
  • the storage unit may have a storage section, a storage space, and the like arranged similarly to the storage 1020 in the server of FIG.
  • the program code can be compressed, for example, in an appropriate form.
  • the storage unit includes computer readable code 103, i.e., code that can be read by, for example, a processor such as 1010, which when executed by the server causes the server to perform various steps in the methods described above.
  • an embodiment or “one or more embodiments” as used herein means that the particular features, structures, or characteristics described in connection with the embodiments are included in at least one embodiment of the invention.
  • the phrase “in one embodiment” herein does not necessarily refer to the same embodiment.
  • any reference signs placed between parentheses shall not be construed as a limitation.
  • the word “comprising” does not exclude the presence of the elements or steps that are not in the claims.
  • the word “a” or “an” preceding a component does not exclude the presence of a plurality of such elements.
  • the invention can be implemented by means of hardware comprising several distinct elements and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means can be embodied by the same hardware item.
  • the use of the words first, second, and third does not indicate any order. These words can be interpreted as names.

Abstract

本发明公开了一种网页中非正文文本的识别系统及方法,涉及正文抽取领域。所述系统包括:网页抓取器适于抓取目标网站的所有网页的数据; DOM树构建单元,适于构建目标网站的每个网页对应的DOM树;DOM树分析单元,适于根据DOM树找出网页中的单元文本段;文本统计单元,适于统计单元文本段在目标网站的所有网页中的出现次数;文本识别单元,适于在所述出现次数大于预定阈值时,将所述单元文本段识别为非正文文本。所述系统及方法,克服了现有方法对于非正文文本识别的滞后问题,并且具有较高的识别准确度。

Description

一种网页中非正文文本的识别系统及方法
技术领域
本发明涉及正文抽取技术领域, 特别涉及一种网页中非正文文本的 识别系统及方法。 背景技术
正文抽取在搜索引擎、 移动阅读等领域有着越来越重要的作用。 正文抽 取常用的技术有基于规则、 基于 DOM ( Document Object Model, 文档对象 模型)树、 基于标记窗、 基于最大文本块等。 这些方法都需要对网站中的非 正文文本, 比如广告、 网站声明等, 进行排除。 如图 la所示是一段网站声 明的代码段示意图, 图 lb是图 la中代码段在网页中的实际展示效果图, 这 种网站声明在网页中非常常见, 对于用户阅读价值不大, 都需要在正文抽取 时进行排除。 然而, 如何有效地识别这些非正文文本, 是一个难题。
现有技术中主要釆用垃圾关键词密度的方法进行非正文文本识别。在基 于垃圾关键词识别非正文文本时, 需要有垃圾关键词构成的词典, 并且不断 对词典进行更新。 对于词典的更新, 只有在发现问题后才能加入新的垃圾关 键词。 因此, 这种方法对于问题的解决具有严重的滞后性, 而且当面对全互 联网的海量数据时, 这种滞后性显的更加突出。 发明内容
鉴于上述问题, 提出了本发明以便提供一种克服上述问题或者至少 部分地解决或者减緩上述问题的网页中非正文文本的识别系统及方法。
根据本发明的一个方面, 提供了一种网页中非正文文本的识别系统, 所述系统包括: 网页抓取器、 DOM树构建单元、 DOM树分析单元、 文本统 计单元和文本识别单元; 所述网页抓取器适于抓取目标网站的所有网页的数 据; 所述 DOM树构建单元, 适于构建目标网站的每个网页对应的 DOM树; 段; 所述文本统计单元, 适于统计所述单元文本段在所述目标网站的所有网 页中的出现次数;所述文本识别单元,适于在所述出现次数大于预定阔值时, 将所述单元文本段识别为非正文文本。 根据本发明的另一个方面,提供了一种网页中非正文文本的识别方法, 其包括步骤:
A: 使用网页抓取器抓取目标网站的所有网页的数据;
B: 构建目标网站的每个网页对应的 DOM树;
C: 根据所述 DOM树找出所述网页中的单元文本段;
D: 统计所述单元文本段在所述目标网站的所有网页中的出现次数; E: 根据所述出现次数, 判断所述单元文本段是否是非正文文本。
其中, 所述步骤 B中, 釆用网页语言对应的解析器构建目标网站的每个 网页对应的 DOM树。
根据本发明的又一个方面, 提供了一种计算机程序, 其包括计算机 可读代码, 当所述计算机可读代码在服务器上运行时, 导致所述服务器 执行根据权利要求 9-16中的任一个所述的网页中非正文文本的识别方法。
根据本发明的再一个方面, 提供了一种计算机可读介质, 其中存储 了如权利要求 17所述的计算机程序。
本发明的有益效果为:
依据本发明实施例的网页中非正文文本的识别系统及方法, 釆用 DOM 树获取每个网页的单元文本段, 进而对单元文本段在目标网站中出现的次数 进行统计, 并将其出现次数与预定阔值进行比较, 从而识别出网站上的非正 文文本, 克服了现有方法对于非正文文本识别的滞后问题, 并且具有较高的 识别准确度, 在搜索引擎中具有广泛的应用前景。
上述说明仅是本发明技术方案的概述, 为了能够更清楚了解本发明 的技术手段, 而可依照说明书的内容予以实施, 并且为了让本发明的上 述和其它目的、 特征和优点能够更明显易懂, 以下特举本发明的具体实 施方式。 附图说明
通过阅读下文优选实施方式的详细描述, 各种其他的优点和益处对 于本领域普通技术人员将变得清楚明了。 附图仅用于示出优选实施方式 的目的, 而并不认为是对本发明的限制。 而且在整个附图中, 用相同的 参考符号表示相同的部件。 在附图中:
图 1 a是一段网站声明的代码段示意图;
图 lb是图 la中代码段在网页中的实际展示效果图; 图 2是本发明实施例所述网页中非正文文本的识别系统的模块结构图; 图 3是所述 DOM树分析单元的内部模块结构图;
图 4是所述文本统计单元的内部模块结构图;
图 5是本发明实施例的网页中非正文文本的识别方法的流程图; 图 6是 HTML网页对应的 DOM树示意图;
图 7是所述步骤 C的流程图;
图 8是所述步骤 D的流程图;
图 9是单元文本段统计原理示意图;
图 10示意性地示出了用于执行根据本发明的方法的服务器的框图; 以及
图 11示意性地示出了用于保持或者携带实现根据本发明的方法的程 序代码的存储单元。 具体实施例
下面结合附图和具体的实施方式对本发明作进一步的描述。
图 2是本发明实施例所述网页中非正文文本的识别系统的模块结构图, 如图 2所示, 所述系统包括: 网页抓取器 100、 DOM树构建单元 200、 DOM 树分析单元 300、 文本统计单元 400和文本识别单元 500。
所述网页抓取器 100适于抓取目标网站的所有网页的数据, 其一般可以 釆用网络蜘蛛、 网页爬虫、 搜索机器人或网络抓取脚本程序。
所述 DOM树构建单元 200, 适于构建所述目标网站的每个网页对应的 DOM树。 所述 DOM树构建单元釆用网页语言对应的解析器, 并且对于 HTML网页, 釆用 HTML解析器。
所述 DOM树分析单元 300 , 适于根据所述 DOM树找出所述网页中的 单元文本段。
图 3是所述 DOM树分析单元的内部模块结构图, 如图 3所示, 所述 DOM树分析单元 300包括: 节点访问模块 301和文本段划分模块 302。
所述节点访问模块 301 , 适于从所述 DOM树的根节点开始, 依次访问 所述 DOM树中的节点, 并将访问到的当前节点发送给所述文本段划分模块 302; 以及适于判断所述 DOM树中是否还有需要访问的节点, 如果是, 将 相应的节点作为新的当前节点发送给所述文本段划分模块 302。
其中, 所述节点访问模块 301可以按照广度优先算法、 深度优先算法或 者其他搜索算法访问所述 DOM树中的节点。由于所述 DOM树分析单元 300 在判定当前节点对应的文本段为单元文本段时,将停止对当前节点的后代节 点的访问, 因此, 所述节点访问模块 301 , 优选适于按照广度优先算法依次 访问所述 DOM树中的节点, 并将访问到的当前节点发送给所述文本段划分 模块 302; 以及适于判断所述 DOM树中是否还有需要访问的当前节点的同 层节点或者下层节点, 如果是, 将相应的同层节点或者下层节点作为新的当 前节点发送给所述文本段划分模块 302。 其中, 广度优先算法又称作宽度优 先搜索, 或横向优先搜索, 是一种从根节点开始, 自上层至下层, 沿着树的 宽度遍历树的节点的算法。
所述文本段划分模块 302, 适于判断当前节点对应的文本段是否满足单 元文本段的条件, 并且在满足条件时, 将所述当前节点对应的文本段作为单 元文本段, 并且通知所述节点访问模块 301停止对所述当前节点的后代节点 的访问。其中,当所述当前节点到其后代节点的最长路径小于等于预定长度, 并且所述当前节点的后代节点中不包含复杂节点时,认为所述当前节点对应 的文本段满足单元文本段的条件。 所述复杂节点包括: 标签 table、 tr、 td、 ul、 ol、 frame、 select、 input、 marquee和 /或 map对应的节点。
所述文本统计单元 400, 适于统计所述单元文本段在所述目标网站的所 有网页中的出现次数。
图 4是所述文本统计单元的内部模块结构图, 如图 4所示, 所述文本统 计单元 400进一步包括: 哈希运算模块 401和统计模块 402。
所述哈希运算模块 401 , 适于对所述单元文本段进行哈希运算, 得到结 果键值。
所述统计模块 402, 适于根据所述结果键值统计所述单元文本段在所述 目标网站的所有网页中的出现次数。
所述文本识别单元 500, 适于判断所述出现次数是否大于预定阔值, 如 果是, 将所述单元文本段识别为非正文文本; 否则, 将所述单元文本段识别 为正文文本。
图 5是本发明实施例的网页中非正文文本的识别方法的流程图,如图 5所 示, 对应所述系统, 所述方法包括步骤:
A: 使用网页抓取器抓取目标网站的所有网页的数据。 所述网页抓取器 一般可以是网络蜘蛛、 网页爬虫、 搜索机器人或网络抓取脚本程序。 所述网 页可以釆用 HTML ( Hypertext Markup Language, 超文本标记语言) 、 XML ( extensible markup language , 可扩展标" i己语言) 、 XHTML ( extensible Hypertext Markup Language, 可扩展超文本标记语言)等标记语言, 为简单 起见, 后续均以 HTML网页为例说明。 这里的所有网页包括所述目标网站的 主网页和子网页。
B: 构建目标网站的每个网页对应的 DOM树。 本实施例中釆用 HTML解 析器构建目标网站的每个网页对应的 DOM树, 本领域技术人员容易想到, 当所述网页釆用其他标记语言时, 可以釆用相应的解析器, 比如釆用 XML 解析器构建 XML网页对应的 DOM树。 图 6是 HTML网页对应的 DOM树示意 图, 如图 6所示, DOM树中的节点对应于 HTML代码中的标签或者文本。
C: 根据所述 DOM树找出所述网页中的单元文本段。
图 7是所述步骤 C的流程图, 如图 7所示, 所述步骤 C中具体包括步 骤:
C 1: 从所述 DOM树的根节点开始, 依次访问所述 DOM树中的节点。 C2: 判断当前节点对应的文本段是否满足单元文本段的条件, 如果是, 停止对所述当前节点的后代节点的访问,将所述当前节点对应的文本段作为 单元文本段, 执行步骤 C3; 否则, 直接执行步骤 C3。
所述步骤 C2具体包括步骤:
C21 : 判断当前节点是否满足以下条件: 所述当前节点到其后代节点的 最长路径小于等于预定长度, 并且所述当前节点的后代节点中不包含复杂节 点; 如果是, 执行步骤 C22; 否则, 执行步骤 C3。 本步骤的含义是, 当所 述当前节点同时满足, 所述当前节点到其后代节点的最长路径小于等于预定 长度, 并且所述当前节点的后代节点中不包含复杂节点时, 将所述当前节点 对应的文本段作为单元文本段。
仍以图 6为例, 图 6中左侧 div节点与其最远的后代节点的距离为 3 , 小于预定距离 4, 同时, 其后代节点中不含所述复杂节点, 因此, 图 6中左 侧 div节点对应的文本段被识别为单元文本段。 需要说明的是, 对所述单元 文本段的识别与所述当前节点的标签名称无关。
所述后代节点包括所述当前节点的各子孙节点, 即在所述当前节点所在 分支上并且位于所述当前节点下层的所有节点。对于所述预定长度的设定以 及所述复杂节点所包括节点的范围可以根据实际使用情况适时调整。 比如, 所述预定长度可以设置为 3或者 4或者 5, 本实施例中, 所述预定长度优选 为 4。 仍以图 6中的 DOM树为例, 对于图 6中左侧的 div节点, 当其作为 当前节点时, 其对应的分支为 div->p->a->text2 , 该 div节点距离其最远的后 代节点 text2的距离为 3 , 小于预定长度 4。本实施例中,所述复杂节点包括: 标签 table、 tr、 td、 ul、 ol、 frame、 select、 input、 marquee和 /或 map对应的 节点。
C22: 停止对所述当前节点的后代节点的访问, 将所述当前节点对应的 文本段作为单元文本段, 执行步骤 C3。
C3: 判断所述 DOM树中是否还有需要访问的节点, 如果是, 将相应的 节点作为新的当前节点, 执行步骤 C2; 否则, 执行所述步骤 D。
所述步骤 C1中, 可以釆用广度优先算法、 深度优先算法或者其他搜索 算法访问所述 DOM树中的节点。 由于本发明实施例所述方法在判定当前节 点对应的文本段为单元文本段时, 将停止对当前节点的后代节点的访问, 因 此, 所述步骤 C1中优选釆用广度优先算法。
当所述步骤 C1中, 按照广度优先算法依次访问所述 DOM树中的节点 时, 所述步骤 C3具体包括步骤:
C31 : 判断所述 DOM树中是否还有未访问的所述当前节点的同层节点, 如果是, 将所述同层节点作为新的当前节点, 执行步骤 C2; 否则, 执行步 骤 C32。 所述同层节点是指与所述当前节点处于同一层的节点, 其可以是所 述当前节点的兄弟节点, 也可以是所述当前节点的非兄弟节点(如图 6中的 text2节点与 text3节点是同层节点但不是兄弟节点) 。
C32: 判断所述 DOM树中是否还有需要访问的所述当前节点的下层节 点, 如果是, 将所述下层节点作为新的当前节点, 执行步骤 C2; 否则, 执 行所述步骤 D。 需要说明的是, 当所述当前节点对应的文本段被识别为单元 文本段时, 所述当前节点的后代节点无需再被访问。
D: 统计所述单元文本段在所述目标网站的所有网页中的出现次数。 图 8是所述步骤 D的流程图 , 如图 8所示, 所述步骤 D具体包括步骤:
D1 : 对所述单元文本段进行哈希运算, 得到结果键值。 本实施例中, 釆 用 MD5 ( Message Digest Algorithm 5 , 消息摘要算法第五版)算法对所述单 元文本段进行哈希运算, 当然本领域技术人员容易想到还可以利用其他类似 算法进行哈希运算。 本实施例中, 在对所述出现次数进行统计时, 建立了以 所述结果键值为 key, 以所述出现次数为 value的 key-value表格, 进而根据 所述 key-value表格判断每个 key值对应的 value值是否大于所述预定阔值, 以识别出每个 key值对应的单元文本段是否是非正文文本。 D2:根据所述结果键值统计所述单元文本段在所述目标网站的所有网页 中的出现次数。
E: 根据所述出现次数, 判断所述单元文本段是否是非正文文本。 所述 步骤 E具体包括步骤: 判断所述出现次数是否大于预定阔值, 如果是, 将所 述单元文本段识别为非正文文本;否则 ,将所述单元文本段识别为正文文本。
图 9是单元文本段统计原理示意图, 如图 9所示, 各所述单元文本段出 现次数的统计范围为所述目标网站的所有网页。 其中, 所述预定阔值可以根 据实际使用情况进行调整, 比如预定阔值可以优选为 100, 或者 90、 150等 等。
本发明实施例所述网页中非正文文本的识别系统及方法, 釆用 DOM树 获取每个网页的单元文本段, 进而对单元文本段在目标网站中出现的次数进 行统计, 并将其出现次数与预定阔值进行比较, 从而识别出网站上的非正文 文本, 克服了现有方法对于非正文文本识别的滞后问题, 并且具有较高的识 别准确度, 在搜索引擎中具有广泛的应用前景。
本发明的各个部件实施例可以以硬件实现, 或者以在一个或者多个 处理器上运行的软件模块实现, 或者以它们的组合实现。 本领域的技术 人员应当理解, 可以在实践中使用微处理器或者数字信号处理器 (DSP ) 全部部件的一些或者全部功能。 本发明还可以实现为用于执行这里所描 述的方法的一部分或者全部的设备或者装置程序 (例如, 计算机程序和 计算机程序产品) 。 这样的实现本发明的程序可以存储在计算机可读介 质上, 或者可以具有一个或者多个信号的形式。 这样的信号可以从因特 网网站上下载得到, 或者在载体信号上提供, 或者以任何其他形式提供。
例如, 图 10示出了可以实现根据本发明的网页中非正文文本的识别 方法的服务器, 例如应用服务器。 该服务器传统上包括处理器 1010和以 存储器 1020 形式的计算机程序产品或者计算机可读介质。 存储器 1020 可以是诸如闪存、 EEPROM (电可擦除可编程只读存储器) 、 EPROM、 硬盘或者 ROM之类的电子存储器。 存储器 1020具有用于执行上述方法 中的任何方法步骤的程序代码 1031的存储空间 1030。 例如, 用于程序代 码的存储空间 1030可以包括分别用于实现上面的方法中的各种步骤的各 个程序代码 1031。 这些程序代码可以从一个或者多个计算机程序产品中 读出或者写入到这一个或者多个计算机程序产品中。 这些计算机程序产 品包括诸如硬盘, 紧致盘(CD ) 、 存储卡或者软盘之类的程序代码载体。 这样的计算机程序产品通常为如参考图 11所述的便携式或者固定存储单 元。 该存储单元可以具有与图 10的服务器中的存储器 1020类似布置的 存储段、 存储空间等。 程序代码可以例如以适当形式进行压缩。 通常, 存储单元包括计算机可读代码 103Γ , 即可以由例如诸如 1010之类的处 理器读取的代码, 这些代码当由服务器运行时, 导致该服务器执行上面 所描述的方法中的各个步骤。
本文中所称的 "一个实施例"、 "实施例"或者"一个或者多个实施例 "意 味着, 结合实施例描述的特定特征、 结构或者特性包括在本发明的至少 一个实施例中。 此外, 请注意, 这里"在一个实施例中"的词语例子不一定 全指同一个实施例。
在此处所提供的说明书中, 说明了大量具体细节。 然而, 能够理解, 本发明的实施例可以在没有这些具体细节的情况下被实践。 在一些实例 中, 并未详细示出公知的方法、 结构和技术, 以便不模糊对本说明书的 理解。
应该注意的是上述实施例对本发明进行说明而不是对本发明进行限 制, 并且本领域技术人员在不脱离所附权利要求的范围的情况下可设计 出替换实施例。 在权利要求中, 不应将位于括号之间的任何参考符号构 造成对权利要求的限制。单词"包含"不排除存在未列在权利要求中的元件 或步骤。 位于元件之前的单词 "一"或"一个"不排除存在多个这样的元件。 本发明可以借助于包括有若干不同元件的硬件以及借助于适当编程的计 算机来实现。 在列举了若干装置的单元权利要求中, 这些装置中的若干 个可以是通过同一个硬件项来具体体现。 单词第一、 第二、 以及第三等 的使用不表示任何顺序。 可将这些单词解释为名称。
此外, 还应当注意, 本说明书中使用的语言主要是为了可读性和教 导的目的而选择的, 而不是为了解释或者限定本发明的主题而选择的。 因此, 在不偏离所附权利要求书的范围和精神的情况下, 对于本技术领 域的普通技术人员来说许多修改和变更都是显而易见的。 对于本发明的 范围, 对本发明所做的公开是说明性的, 而非限制性的, 本发明的范围 由所附权利要求书限定。

Claims

权 利 要 求
1、 一种网页中非正文文本的识别系统, 其包括: 网页抓取器、 DOM树 构建单元、 DOM树分析单元、 文本统计单元和文本识别单元;
所述网页抓取器适于抓取目标网站的所有网页的数据;
所述 DOM树构建单元,适于构建目标网站的每个网页对应的 DOM树; 所述 DOM树分析单元, 适于根据所述 DOM树找出所述网页中的单元 文本段;
所述文本统计单元, 适于统计所述单元文本段在所述目标网站的所有网 页中的出现次数;
所述文本识别单元, 适于在所述出现次数大于预定阈值时, 将所述单元 文本段识别为非正文文本。
2、 如权利要求 1所述的系统, 其中, 所述 DOM树构建单元釆用网页 语言对应的解析器。
3、 如权利要求 1所述的系统, 其中, 所述 DOM树分析单元包括: 节 点访问模块和文本段划分模块;
所述节点访问模块, 适于从所述 DOM树的根节点开始, 依次访问所述 DOM树中的节点, 并将访问到的当前节点发送给所述文本段划分模块; 以 及适于判断所述 DOM树中是否还有需要访问的节点, 如果是, 将相应的节 点作为新的当前节点发送给所述文本段划分模块;
所述文本段划分模块, 适于判断当前节点对应的文本段是否满足单元文 本段的条件, 并且在满足条件时, 将所述当前节点对应的文本段作为单元文 本段, 并且通知所述节点访问模块停止对所述当前节点的后代节点的访问。
4、 如权利要求 3所述的系统, 其中, 所述节点访问模块, 适于从所述 DOM树的根节点开始, 按照广度优先算法依次访问所述 DOM树中的节点, 并将访问到的当前节点发送给所述文本段划分模块; 以及适于判断所述 DOM树中是否还有需要访问的当前节点的同层节点或者下层节点,如果是, 将相应的同层节点或者下层节点作为新的当前节点发送给所述文本段划分 模块。
5、 如权利要求 3所述的系统, 其中, 当所述当前节点到其后代节点的 最长路径小于等于预定长度, 并且所述当前节点的后代节点中不包含复杂节 点时, 认为所述当前节点对应的文本段满足单元文本段的条件。
6、 如权利要求 5所述的系统, 其中, 所述复杂节点包括: 标签 table、 tr、 td、 ul、 ol、 frame、 select、 input、 marquee和 /或 map对应的节点。
7、 如权利要求 1所述的系统, 其中, 所述文本统计单元包括: 哈希运 算模块和统计模块;
所述哈希运算模块, 适于对所述单元文本段进行哈希运算, 得到结果键 值;
所述统计模块, 适于根据所述结果键值统计所述单元文本段在所述目标 网站的所有网页中的出现次数。
8、 如权利要求 1所述的系统, 其中, 所述文本识别单元, 还适于在所 述出现次数小于等于所述预定阔值时, 将所述单元文本段识别为正文文本。
9、 一种网页中非正文文本的识别方法, 其包括步骤:
A: 使用网页抓取器抓取目标网站的所有网页的数据;
B: 构建目标网站的每个网页对应的 DOM树;
C: 根据所述 DOM树找出所述网页中的单元文本段;
D: 统计所述单元文本段在所述目标网站的所有网页中的出现次数;
E: 根据所述出现次数, 判断所述单元文本段是否是非正文文本。
10、 如权利要求 9所述的方法, 其中, 所述步骤 B中, 釆用网页语言对 应的解析器构建目标网站的每个网页对应的 DOM树。
11、 如权利要求 9所述的方法, 其中, 所述步骤 C中具体包括步骤: C1 : 从所述 DOM树的根节点开始, 依次访问所述 DOM树中的节点;
C2: 判断当前节点对应的文本段是否满足单元文本段的条件, 如果是, 停止对所述当前节点的后代节点的访问,将所述当前节点对应的文本段作为 单元文本段, 执行步骤 C3; 否则, 直接执行步骤 C3;
C3: 判断所述 DOM树中是否还有需要访问的节点, 如果是, 将相应的 节点作为新的当前节点, 执行步骤 C2; 否则, 执行所述步骤 D。
12、 如权利要求 11所述的方法, 其中, 所述步骤 C2具体包括步骤: C21 : 判断当前节点是否满足以下条件: 所述当前节点到其后代节点的 最长路径小于等于预定长度, 并且所述当前节点的后代节点中不包含复杂节 点; 如果是, 执行步骤 C22; 否则, 执行步骤 C3;
C22: 停止对所述当前节点的后代节点的访问, 将所述当前节点对应的 文本段作为单元文本段, 执行步骤 C3。
13、 如权利要求 12所述的方法, 其中, 所述复杂节点包括: 标签 table、 tr、 td、 ul、 ol、 frame、 select、 input、 marquee和 /或 map对应的节点。
14、 如权利要求 11所述的方法, 其中, 所述步骤 C1中, 按照广度优先 算法依次访问所述 DOM树中的节点;
所述步骤 C3具体包括步骤:
C31 : 判断所述 DOM树中是否还有未访问的所述当前节点的同层节点, 如果是, 将所述同层节点作为新的当前节点, 执行步骤 C2; 否则, 执行步 骤 C32;
C32: 判断所述 DOM树中是否还有需要访问的所述当前节点的下层节 点, 如果是, 将所述下层节点作为新的当前节点, 执行步骤 C2; 否则, 执 行所述步骤 D。
15、 如权利要求 9所述的方法, 其中, 所述步骤 D具体包括步骤: D1 : 对所述单元文本段进行哈希运算, 得到结果键值;
D2:根据所述结果键值统计所述单元文本段在所述目标网站的所有网页 中的出现次数。
16、 如权利要求 9所述的方法, 其中, 所述步骤 E具体包括步骤: 判断 所述出现次数是否大于预定阈值, 如果是, 将所述单元文本段识别为非正文 文本; 否则, 将所述单元文本段识别为正文文本。
17、 一种计算机程序, 包括计算机可读代码, 当所述计算机可读代 码在服务器上运行时, 导致所述服务器执行根据权利要求 9-16中的任一 个所述的网页中非正文文本的识别方法。
18、 一种计算机可读介质, 其中存储了如权利要求 17所述的计算机 程序。
PCT/CN2013/077102 2012-06-25 2013-06-09 一种网页中非正文文本的识别系统及方法 WO2014000571A1 (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
US14/411,013 US10042827B2 (en) 2012-06-25 2013-06-09 System and method for recognizing non-body text in webpage

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201210214385.2 2012-06-25
CN201210214385.2A CN102779172B (zh) 2012-06-25 2012-06-25 一种网页中非正文文本的识别系统及方法

Publications (1)

Publication Number Publication Date
WO2014000571A1 true WO2014000571A1 (zh) 2014-01-03

Family

ID=47124084

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2013/077102 WO2014000571A1 (zh) 2012-06-25 2013-06-09 一种网页中非正文文本的识别系统及方法

Country Status (3)

Country Link
US (1) US10042827B2 (zh)
CN (1) CN102779172B (zh)
WO (1) WO2014000571A1 (zh)

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102779172B (zh) * 2012-06-25 2016-06-01 北京奇虎科技有限公司 一种网页中非正文文本的识别系统及方法
CN103678510B (zh) * 2013-11-25 2018-02-02 北京奇虎科技有限公司 对网页提供可视化标注的方法及装置
CN105740355B (zh) * 2016-01-26 2019-03-26 中国人民解放军国防科学技术大学 基于聚集文本密度的网页正文提取方法及装置
CN107861868A (zh) * 2017-10-31 2018-03-30 郑州云海信息技术有限公司 一种提取自动化测试对象的方法及系统
CN110020302A (zh) * 2017-11-16 2019-07-16 富士通株式会社 提取网页内容的方法和网页内容提取装置
CN109948089A (zh) * 2019-02-21 2019-06-28 中国海洋大学 一种提取网页正文的方法及装置

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101251855A (zh) * 2008-03-27 2008-08-27 腾讯科技(深圳)有限公司 一种互联网网页清洗方法、系统及设备
US20090063500A1 (en) * 2007-08-31 2009-03-05 Microsoft Corporation Extracting data content items using template matching
CN102184189A (zh) * 2011-04-18 2011-09-14 北京理工大学 基于dom节点文本密度的网页核心块确定方法
CN102779172A (zh) * 2012-06-25 2012-11-14 北京奇虎科技有限公司 一种网页中非正文文本的识别系统及方法

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6635089B1 (en) * 1999-01-13 2003-10-21 International Business Machines Corporation Method for producing composite XML document object model trees using dynamic data retrievals
CN1311336C (zh) * 2002-04-15 2007-04-18 皇家飞利浦电子股份有限公司 用于显示文档的方法和系统
US7698317B2 (en) * 2007-04-20 2010-04-13 Yahoo! Inc. Techniques for detecting duplicate web pages
CN101872350A (zh) * 2009-04-24 2010-10-27 富士通株式会社 网页正文抽取方法和装置
US8751953B2 (en) * 2010-06-04 2014-06-10 Apple Inc Progress indicators for loading content

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090063500A1 (en) * 2007-08-31 2009-03-05 Microsoft Corporation Extracting data content items using template matching
CN101251855A (zh) * 2008-03-27 2008-08-27 腾讯科技(深圳)有限公司 一种互联网网页清洗方法、系统及设备
CN102184189A (zh) * 2011-04-18 2011-09-14 北京理工大学 基于dom节点文本密度的网页核心块确定方法
CN102779172A (zh) * 2012-06-25 2012-11-14 北京奇虎科技有限公司 一种网页中非正文文本的识别系统及方法

Also Published As

Publication number Publication date
CN102779172A (zh) 2012-11-14
CN102779172B (zh) 2016-06-01
US20150205769A1 (en) 2015-07-23
US10042827B2 (en) 2018-08-07

Similar Documents

Publication Publication Date Title
US9298680B2 (en) Display of hypertext documents grouped according to their affinity
US7941420B2 (en) Method for organizing structurally similar web pages from a web site
WO2019218514A1 (zh) 网页目标信息的提取方法、装置及存储介质
WO2014000571A1 (zh) 一种网页中非正文文本的识别系统及方法
US7818324B1 (en) Searching indexed and non-indexed resources for content
CN105359139B (zh) 安全信息管理系统及安全信息管理方法
CN102436563B (zh) 一种检测页面篡改的方法及装置
WO2014000576A1 (zh) 一种网络搜索方法及网络搜索系统
US20080172220A1 (en) Incorrect Hyperlink Detecting Apparatus and Method
WO2018095411A1 (zh) 一种网页聚类方法及装置
US20150046781A1 (en) Browsing images via mined hyperlinked text snippets
CN108874996A (zh) 网站分类方法及装置
CN102591965A (zh) 一种黑链检测的方法及装置
WO2020211130A1 (zh) 一种网站暗链检测方法和装置
WO2017063596A1 (zh) 一种处理网站地图的方法、装置及设备
CN112579476A (zh) 一种漏洞和软件对齐的方法、装置以及存储介质
WO2022179128A1 (zh) 基于爬虫的数据抓取方法、装置、计算机设备及存储介质
US20120005207A1 (en) Method and system for web extraction
CN103853771B (zh) 一种搜索结果的推送方法及系统
CN113849718A (zh) 互联网烟草科技情报信息自动采集装置、方法与存储介质
WO2021068681A1 (zh) 标签分析方法、装置及计算机可读存储介质
WO2020073493A1 (zh) Sql注入漏洞检测方法、装置、设备及可读存储介质
US10380195B1 (en) Grouping documents by content similarity
CN104750692B (zh) 一种信息处理方法、信息检索方法及其对应的装置
CN104077353A (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: 13810488

Country of ref document: EP

Kind code of ref document: A1

WWE Wipo information: entry into national phase

Ref document number: 14411013

Country of ref document: US

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 13810488

Country of ref document: EP

Kind code of ref document: A1