html2article java_mirrors/html2article - html2article - Gitea: Git with a cup of tea

基于文本密度的html2article实现[golang]

Install

go get -u -v github.com/sundy-li/html2article

Performance

Accuracy: >= 98%

Qps: 2w/s , 0.06ms/op go test -bench=. BenchmarkExtract-4 20000 66341 ns/op

说明(对比其他开源实现,可能是目前最快的html2article实现,我们测试的数据集约3kw来自于微信公众号,各大类中文科技媒体历史文章,目前能达到98%以上准确率)

除了必要dom解析以及时间解析, 为了高效率实现, 避免了过多的正则匹配

Examples

package main

import (

"github.com/sundy-li/html2article"

)

func main() {

urlStr := "https://www.leiphone.com/news/201602/DsiQtR6c1jCu7iwA.html"

ext, err := html2article.NewFromUrl(urlStr)

if err != nil {

panic(err)

}

article, err := ext.ToArticle()

if err != nil {

panic(err)

}

println("article title is =>", article.Title)

println("article publishtime is =>", article.Publishtime) //using UTC timezone

println("article content is =>", article.Content)

//parse the article to be readability

article.Readable(urlStr)

println("read=>", article.ReadContent)

}

Options

ext.SetOption(&html2article.Option{

AccurateTitle: true, //Get the accurate title instead of from title tag

RemoveNoise: false, //Remove the noise node such as some footer

})

Algorithm

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值