Skip to main content

Newspaper: Article scraping & curation

https://badge.fury.io/py/newspaper.png

Newspaper is a Python 2 library for extracting & curating articles from the web. It is inspired by requests for its simplicity and powered by lxml for its speed.

We support 10+ languages and everything is in unicode!

>>> import newspaper
>>> newspaper.languages()

Your available langauges are:
input code      full name

  ar              Arabic
  de              German
  en              English
  es              Spanish
  fr              French
  it              Italian
  ko              Korean
  no              Norwegian
  pt              Portugease
  sv              Swedish
  zh              Chinese

Praise:

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

A Glance:

>>> import newspaper

>>> cnn_paper = newspaper.build('http://cnn.com')

>>> for article in cnn_paper.articles:
>>>     print article.url
u'http://www.cnn.com/2013/11/27/justice/tucson-arizona-captive-girls/'
u'http://www.cnn.com/2013/12/11/us/texas-teen-dwi-wreck/index.html'
...

>>> for category in cnn_paper.category_urls():
>>>     print category

u'http://lifestyle.cnn.com'
u'http://cnn.com/world'
u'http://tech.cnn.com'
...
>>> article = cnn_paper.articles[0]
>>> article.download()

>>> article.html
u'<!DOCTYPE HTML><html itemscope itemtype="http://...'
>>> article.parse()

>>> article.authors
[u'Leigh Ann Caldwell', 'John Honway']

>>> article.text
u'Washington (CNN) -- Not everyone subscribes to a New Year's resolution...'

>>> article.top_image
u'http://someCDN.com/blah/blah/blah/file.png'

>>> article.movies
[u'http://youtube.com/path/to/link.com', ...]
>>> article.nlp()

>>> article.keywords
['New Years', 'resolution', ...]

>>> article.summary
u'The study shows that 93% of people ...'

Newspaper has seamless language extraction and detection. If no language is specified, Newspaper will attempt to auto detect a language.

>>> from newspaper import Article
>>> 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
港特首梁振英就住宅违建事件道歉

If you are certain that an entire news source is in one language, go ahead and use the same api :)

>>> import newspaper
>>> sina_paper = newspaper.build('http://www.sina.com.cn/', langauge='zh')

>>> for category in sina_paper.category_urls():
>>>     print category
u'http://health.sina.com.cn'
u'http://eladies.sina.com.cn'
u'http://english.sina.com'
...

>>> article = sina_paper.articles[0]
>>> article.download()
>>> article.parse()

>>> print article.text
新浪武汉汽车综合 随着汽车市场的日趋成熟,
传统的“集全家之力抱得爱车归”的全额购车模式已然过时,
另一种轻松的新兴 车模式――金融购车正逐步成为时下消费者购
买爱车最为时尚的消费理念,他们认为,这种新颖的购车
模式既能在短期内
...

>>> print article.title
两年双免0手续0利率 科鲁兹掀背金融轻松购_武汉车市_武汉汽
车网_新浪汽车_新浪网

Documentation

Check out The Documentation for full and detailed guides using newspaper.

Features

  • Works in 10+ languages (English, Chinese, German, Arabic, …)

  • Multi-threaded article download framework

  • News url identification

  • Text extraction from html

  • Top image extraction from html

  • All image extraction from html

  • Keyword extraction from text

  • Summary extraction from text

  • Author extraction from text

  • Google trending terms extraction

Get it now

Installing newspaper is simple with pip. However, you will run into fixable issues if you are trying to install on ubuntu.

If you are not using ubuntu, install with the following:

$ pip install newspaper

$ curl https://raw.github.com/codelucas/newspaper/master/download_corpora.py | python2.7

If you are, install using the following:

$ apt-get install libxml2-dev libxslt-dev

$ easy_install lxml  # NOT PIP

$ pip install newspaper

$ curl https://raw.github.com/codelucas/newspaper/master/download_corpora.py | python2.7

It is also important to note that the line

$ curl https://raw.github.com/codelucas/newspaper/master/download_corpora.py | python2.7

is not needed unless you need the natural language, nlp(), features like keywords extraction and summarization.

If you are using ubuntu and are still running into gcc compile errors when installing lxml, try installing libxslt1-dev instead of libxslt-dev.

Todo List

  • Add a “follow_robots.txt” option in the config object.

  • Bake in the CSSSelect and BeautifulSoup dependencies

Metadata

Release files for newspaper 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for newspaper 0.0.6
File Size Uploaded Provenance Actions
newspaper-0.0.6.tar.gz 7.0 MB Without provenance Details for newspaper-0.0.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for newspaper 0.0.6
File Interpreter ABI Platform Actions
newspaper-0.0.6.macosx-10.8-intel.exe Details for newspaper-0.0.6.macosx-10.8-intel.exe

Total release size: 14.1 MB

Release files / newspaper-0.0.6.tar.gz

Download URL newspaper-0.0.6.tar.gz
Size 7.0 MB
Tags Source
SHA-256 checksum
How to use checksums
7bb92ecf4ef26dc3121b798e933dfc4cce3eb95d1d9e4ae01887231f12e30f9d
BLAKE2b-256 checksum
How to use checksums
d77fddcd5263d1fa14936786b01f62e75a4f806f98cb2255587af00ccb08b97b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / newspaper-0.0.6.macosx-10.8-intel.exe

Download URL newspaper-0.0.6.macosx-10.8-intel.exe
Size 7.1 MB
Tags Source
SHA-256 checksum
How to use checksums
5a5ad96da13bbd2688ca12d9c116dfb048d90e096248ee143b5b599cb26bba07
BLAKE2b-256 checksum
How to use checksums
a684d99c7c6202a486a3f8a8eae10185e7ab15a1be2f3667ae92b5f7b4404c98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for newspaper 0.0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page