赞
踩
用到python的newspaper库
from newspaper import Article
news = Article(link.strip(), language='zh')
news.download()
news.parse()
print(news.text)
计算识别长度是否合格
不合格的从URL访问网页转成图片提取
(为什么不直接提取html中的文字:转成图片成功率更大,且去除html标签有js残留)
图1 counts1为从源码中去除html标签的成功率
图2 counts1为URL访问网页转成图片的成功率PS:只要转成图片必能识别文字
URL访问网页转成图片:
import imgkit
path_wkimg = r'H:\wkhtmltopdf\bin\wkhtmltoimage.exe' # 工具路径
cfg = imgkit.config(wkhtmltoimage=path_wkimg)
imgkit.from_url(link, str(num) + '.jpg', config=cfg)
全部代码附上:
import urllib
from newspaper import Article
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。