Redability

在写爬虫进行舆情分析、情感分析等内容时,我们经常爬取博客、新闻等长篇大论的文章,在一个网页上,根据网页布局,人眼可以很明确的确定哪些元素是文章主体。人眼既然能够识别,那么机器必然也是能够识别的。如果给定一片HTML文档,机器学习返回文章主体所在的元素,那样在写爬虫时就可以避免F12打开控制台查看元素名称了。

从网页中提取出主要内容,一直是一个比较有挑战的算法。Readability是其中一个很不错的实现。Readability之前是开源的,后来不再公开了。
Readability通过遍历Dom对象,通过标签和常用文字的加减权,来重新整合出页面的内容。
Readability也是一款chrome插件,可以提取网页正文发送到手机,这样就可以空闲时在移动端详细阅读正文。

python:https://github.com/timbertson/python-readability
java:https://github.com/chimbori/crux
nodejs版本:https://github.com/luin/readability
php 版本:https://github.com/feelinglucky/php-readability
JS版本:https://github.com/mozilla/readability
Swift版本:https://github.com/exyte/ReadabilityKit
Ruby版本:https://github.com/cantino/ruby-readability

参考资料

https://www.biaodianfu.com/about

原文地址:https://www.cnblogs.com/weiyinfu/p/8728682.html