简化的python文章发现和提取。(删除图像处理)
newspaper3k-no-image的Python项目详细描述
灵感来源于requests的简洁性,动力来源于lxml的速度:
“Newspaper is an amazing python library for extracting & curating articles.” – tweeted by Kenneth Reitz, Author of requests
“Newspaper delivers Instapaper style article extraction.” – The Changelog
报纸是python3库!或者,查看我们的已弃用和错误Python2 branch
一瞥:
>>> fromnewspaperimportArticle>>> url='http://fox13now.com/2013/12/30/new-year-new-laws-obamacare-pot-guns-and-drones/'>>> article=Article(url)
>>> article.download()>>> article.html'<!DOCTYPE HTML><html itemscope itemtype="http://...'
>>> article.parse()>>> article.authors['Leigh Ann Caldwell', 'John Honway'] >>> article.publish_datedatetime.datetime(2013, 12, 30, 0, 0) >>> article.text'Washington (CNN) -- Not everyone subscribes to a New Year's resolution...' >>> article.top_image'http://someCDN.com/blah/blah/blah/file.png' >>> article.movies['http://youtube.com/path/to/link.com', ...]
>>> article.nlp()>>> article.keywords['New Years', 'resolution', ...] >>> article.summary'The study shows that 93% of people ...'
>>> importnewspaper>>> cnn_paper=newspaper.build('http://cnn.com')>>> forarticleincnn_paper.articles:>>> print(article.url)http://www.cnn.com/2013/11/27/justice/tucson-arizona-captive-girls/ http://www.cnn.com/2013/12/11/us/texas-teen-dwi-wreck/index.html ...>>> forcategoryincnn_paper.category_urls():>>> print(category) http://lifestyle.cnn.com http://cnn.com/world http://tech.cnn.com ...>>> cnn_article=cnn_paper.articles[0]>>> cnn_article.download()>>> cnn_article.parse()>>> cnn_article.nlp()...
>>> fromnewspaperimportfulltext>>> html=requests.get(...).text>>> text=fulltext(html)
报纸可以无缝地提取和检测语言。 如果没有指定语言,报纸将尝试自动检测语言。
>>> fromnewspaperimportArticle>>> url='http://www.bbc.co.uk/zhongwen/simp/chinese_news/2012/12/121210_hongkong_politics.shtml'>>> a=Article(url,language='zh')# Chinese>>> a.download()>>> a.parse()>>> print(a.text[:150])香港行政长官梁振英在各方压力下就其大宅的违章建 筑(僭建)问题到立法会接受质询,并向香港民众道歉。 梁振英在星期二(12月10日)的答问大会开始之际 在其演说中道歉,但强调他在违章建筑问题上没有隐瞒的 意图和动机。 一些亲北京阵营议员欢迎梁振英道歉, 且认为应能获得香港民众接受,但这些议员也质问梁振英有 >>> print(a.title)港特首梁振英就住宅违建事件道歉
如果您确定一个完整的新闻源是一种语言,继续使用相同的api:)
>>> importnewspaper>>> sina_paper=newspaper.build('http://www.sina.com.cn/',language='zh')>>> forcategoryinsina_paper.category_urls():>>> print(category)http://health.sina.com.cn http://eladies.sina.com.cn http://english.sina.com ...>>> article=sina_paper.articles[0]>>> article.download()>>> article.parse()>>> print(article.text)新浪武汉汽车综合 随着汽车市场的日趋成熟, 传统的“集全家之力抱得爱车归”的全额购车模式已然过时, 另一种轻松的新兴 车模式――金融购车正逐步成为时下消费者购 买爱车最为时尚的消费理念,他们认为,这种新颖的购车 模式既能在短期内 ...>>> print(article.title)两年双免0手续0利率 科鲁兹掀背金融轻松购_武汉车市_武汉汽 车网_新浪汽车_新浪网
功能
- 多线程文章下载框架
- 新闻URL标识
- 从HTML提取文本
- 从HTML提取顶级图像
- 从HTML中提取所有图像
- 从文本中提取关键字
- 从文本中提取摘要
- 从文本中提取作者
- 谷歌趋势术语提取
- 可使用10多种语言(英语、中文、德语、阿拉伯语等)
>>> importnewspaper>>> newspaper.languages() Your available languages are: input code full name ar Arabic ru Russian nl Dutch de German en English es Spanish fr French he Hebrew it Italian ko Korean no Norwegian fa Persian pl Polish pt Portuguese sv Swedish hu Hungarian fi Finnish da Danish zh Chinese id Indonesian vi Vietnamese sw Swahili tr Turkish el Greek uk Ukrainian bg Bulgarian hr Croatian ro Romanian sl Slovenian sr Serbian et Estonian ja Japanese be Belarusian lt Lithuanian
立即获取
运行pip3 install newspaper3k
不是pip3 install newspaper
在python3上必须安装newspaper3k,而不是newspaper。newspaper是我们的python2库。 虽然用pip安装报纸很简单,但是 如果你试图在ubuntu上安装,就会遇到可修复的问题。
如果您在debian/ubuntu上,请使用以下命令安装:
安装pip3安装newspaper3k包所需的命令:
$ sudo apt-get install python3-pip
python开发版本,python.h:
$ sudo apt-get install python-dev
LXML要求:
$ sudo apt-get install libxml2-dev libxslt-dev
对于PIL识别.jpg图像:
$ sudo apt-get install libjpeg-dev zlib1g-dev libpng12-dev
注意:如果在安装libpng12-dev时发现问题,请尝试安装libpng-dev。
下载NLP相关语料库:
$ curl https://raw.githubusercontent.com/codelucas/newspaper/master/download_corpora.py | python3
通过pip安装分发版:
$ pip3 install newspaper3k
如果您在OSX上,请使用以下方法安装,您可以同时使用自制或MacPorts:
$ brew install libxml2 libxslt $ brew install libtiff libjpeg webp little-cms2 $ pip3 install newspaper3k $ curl https://raw.githubusercontent.com/codelucas/newspaper/master/download_corpora.py | python3
否则,请使用以下命令安装:
注意:您仍然很可能需要通过包管理器安装以下库
- PIL:^{TT10}$^{TT11}$^{TT8}$
- lxml:libxml2-devlibxslt-dev
- python开发版本:python-dev
$ pip3 install newspaper3k $ curl https://raw.githubusercontent.com/codelucas/newspaper/master/download_corpora.py | python3
开发
如果你想为报纸项目做贡献和黑客攻击,请随意克隆 本地存储库的开发版本:
git clone git://github.com/codelucas/newspaper.git
一旦有了源代码的副本,就可以将其嵌入到python包中, 或者轻松地将其安装到您的网站包中:
$ pip3 install -r requirements.txt $ python3 setup.py install
请随意给我们的测试套件一个机会,一切都是嘲笑!:
$ python3 tests/unit_tests.py
计划调整我们的全文算法?添加fulltext参数:
$ python3 tests/unit_tests.py fulltext
演示
在此处查看正在工作的联机演示:http://newspaper-demo.herokuapp.com 这是另一个在线演示:http://newspaper.chinazt.cc/
许可证
由Lucas Ou-Yang编写和维护。
Parse.ly赞助了一些关于报纸的工作,特别是 自动提取。
报纸使用了很多python-goose’s解析代码。查看他们的许可证here。
如果您遇到问题或只是想 谈谈这个图书馆的未来和新闻采编的总体情况!