需 Python 3.10 及以上;使用 Google News 功能要额外安装 pip install newspaper4k[gnews];语言检测错误时可能提取不到正文,需显式指定 language
newspaper4k
AndyTheFactoryMIT活跃维护从新闻网站批量抓取文章正文、标题和元数据的 Python 库,是 Newspaper3k 的维护分支,适合做新闻语料采集和数据集准备。
📰 Newspaper4k a fork of the beloved Newspaper3k. Extraction of articles, titles, and metadata from news websites.
pip install newspaper4k
python -m newspaper --url="https://edition.cnn.com/2023/11/17/success/job-seekers-use-ai/index.html" --language=en --output-format=json --output-file=article.jsonREADME 未说明,纯 Python 库,无需 GPU
newspaper3k 的活跃续作,从新闻网站抓取正文、标题与元数据
从新闻网站批量抓取文章正文、标题和元数据的 Python 库,是 Newspaper3k 的维护分支,适合做新闻语料采集和数据集准备。
核心能力
- 沿用 newspaper3k 全部类与方法,旧 API 调用可直接迁移
- 多线程下载文章,线程数可通过 number_threads 配置
- 自动检测网站分类结构与新闻 URL,构建 Source 抓取整站
- 提取正文、标题、作者、发布日期、主图与全部图片
- 内置 NLP 生成关键词与摘要,支持 80+ 种语言
容易踩的坑
- 0.9.6.1Version 0.9.6.1 - Security fix: SSRF protection for outbound requests最新正式版2026-11-01 · 2026-11-01 20:49 UTC
Highlights
- Security fix (CWE-918, SSRF):
Article.parse()fetches images by default, and it took image URLs straight from the page (<img src>,og:image). The only validation was a URL scheme check. A page an attacker controls or influences could therefore make the server request internal addresses such as127.0.0.1, private ranges, or cloud metadata endpoints like169.254.169.254. Versions up to and including 0.9.6 are affected. - Outbound requests are now checked: every request made through
do_requestis rejected withPrivateHostErrorunless the host resolves to a public IP. Redirect targets are checked at every hop, so a public URL can't bounce to an internal host. This coversread_more_linktargets, meta-refresh targets, andSourcecategory, feed and article URLs. - Image fetching: image downloads, which don't go through
do_request, have their own check and follow redirects by hand with a check on each hop. - New option
allow_private_hosts(defaultFalse): set it toTrueto fetch private or internal hosts again. - NLP requires
nltk >=3.10: the Punkt tokenizer in nltk 3.10 splits sentences after closing quotes, which changes the generated summaries.
Breaking changes
- Requests to
localhost, private IP ranges, or internal hostnames now fail unlessallow_private_hosts=True. This includes article URLs you pass in yourself. - The
nlpextra now needsnltk >=3.10. Summaries can differ from earlier versions because of the sentence-splitting change. - nltk 3.10 rejects an
nltk_datadirectory that is writable by another account. PointNLTK_DATAat a directory you own if you hit aLookupErrorforpunkt_tab.
Upgrade advice
Anyone using
newspaper4kto parse pages from untrusted or user-supplied sources should upgrade. If you must stay on an older version, setfetch_images=Falseto disable image fetching and validate user-supplied URLs yourself.Known limitations
DNS rebinding between the host check and the connection is not prevented. For hard guarantees, also restrict outbound traffic at the network level.
What's Changed
- Block SSRF in image extraction, meta refresh,
read_more_linkandSourceURL handling, withallow_private_hoststo opt out - Add
PrivateHostErrorandnetwork.is_public_url() - Update NLP test fixtures for nltk 3.10 Punkt and require
nltk >=3.10
Full Changelog: https://github.com/AndyTheFactory/newspaper4k/compare/0.9.6...0.9.7
- Security fix (CWE-918, SSRF):
- 0.9.6Version 0.9.6 - PyInstaller support, small fixes, more documentation, some reworks2026-07-19 · 2026-07-19 16:45 UTC
查看更新说明
- Added native PyInstaller support
- Fixed article configuration isolation
- Improved extraction and duplicate detection
- Added
lxml6.x support - Expanded documentation and test coverage
What's Changed
- Add PyInstaller hooks for bundling newspaper resources (
[66f2c3a](https://github.com/AndyTheFactory/newspaper4k/commit/66f2c3a4efd16a1c4f9cb04bc5d32f1ab7f59dc0)) - Prevent duplicate articles using normalized URLs and content fingerprints (
[9c38f43](https://github.com/AndyTheFactory/newspaper4k/commit/9c38f43169abada4f1c6e09a20819709d8ebffef)) - Fix article language configuration across source articles (
[f862726](https://github.com/AndyTheFactory/newspaper4k/commit/f8627261d905f1ea8f1f917c55a2ef795252ed09)) - Improve extractor reliability and metadata handling (
[ae06add](https://github.com/AndyTheFactory/newspaper4k/commit/ae06addb443cf88f597a138fe80f2701c2660006)) - Relax the
lxmlupper bound to support 6.x ([31abed9](https://github.com/AndyTheFactory/newspaper4k/commit/31abed974fae8d3e7a621abf698fceb3614263dd))
Full Changelog:
[0.9.5...0.9.6](https://github.com/AndyTheFactory/newspaper4k/compare/0.9.5...0.9.6) - 0.9.5Version 0.9.5 - improvements Google News and honor robots.txt2026-02-28 · 2026-02-28 14:33 UTC
查看更新说明
- lang: Add ISO 639-3 language code support for Kurdish (ckb, kmr)
- tests: add robots tests
- feat: added robots.txt check with hook in do_request
- feat: add hooks to get_html
- parse: prioritize
datePublishedoverdateCreatedin JSON-LD extraction - docs: Readme improvements
- feat: add
nltkas an optional dependency for leaner deployments - docs: added additional documentation for GoogleNews and Cloudscraper integration
- rework: type annotations removed deprecated types (python 3.10+)
What's Changed
- lang: Add ISO 639-3 language code support for Kurdish (ckb, kmr) by Muzaffer Cikay in https://github.com/AndyTheFactory/newspaper4k/pull/691
- tests: add robots tests by Andrei in https://github.com/AndyTheFactory/newspaper4k/commit/030e50d2f41f77e139030ad8374342ed1e36f398
- feat: added robots.txt check with hook in
do_requestby Andrei in https://github.com/AndyTheFactory/newspaper4k/commit/62dece9ece919c1947a06843c59fdd86d9a45ea9 - feat: add hooks to
get_htmlby Andrei in https://github.com/AndyTheFactory/newspaper4k/commit/708cc10ff43c1d0dff48860673677aaa9f473d7d - parse: prioritize
datePublishedoverdateCreatedin JSON-LD extraction by Pontus Svensson in https://github.com/AndyTheFactory/newspaper4k/commit/cdadb9ec48fe19e4f0c35478bdd4420c14d73084 - docs: Readme improvements by Andrei in https://github.com/AndyTheFactory/newspaper4k/commit/18ca21c888da17e94e3d4320e25e360ff24cb530
- feat: add
nltkas an optional dependency for leaner deployments by Andrei in https://github.com/AndyTheFactory/newspaper4k/commit/e0734594ea64f3904fb374ab27de563b94565c0b - docs: added additional documentation for GoogleNews and Cloudscraper integration by Andrei in https://github.com/AndyTheFactory/newspaper4k/commit/aceb8535932938c7c44f7ce3f35c9deb87b4e0e6
- rework: type annotations removed deprecated types (python 3.10+) by Andrei in https://github.com/AndyTheFactory/newspaper4k/commit/bd82a41225bdc9a883c0f9f2da1fec178cc8aa81
Bugs Fixed
- skip null entries in JSON-LD arrays during extraction (fix #692) by ghxm in https://github.com/AndyTheFactory/newspaper4k/commit/77d6cccf27dc94db47e1d83d944473e6a805c35d
- ArticleException f-string not interpolating
status_code(fix #684) by Andrei in https://github.com/AndyTheFactory/newspaper4k/commit/7caa2a5e7efb25d3e8c898540322a995ff1c6168 - accept relative paths for categories (PR #667) by BRNMan in https://github.com/AndyTheFactory/newspaper4k/pull/667
- use w3lib to detect webpage encoding by Andrei in https://github.com/AndyTheFactory/newspaper4k/commit/3bd4f006301aa8a83b723881db133564e61268ee
New Contributors
- Muzaffer Cikay made their first contribution in https://github.com/AndyTheFactory/newspaper4k/pull/691
Full Changelog: https://github.com/AndyTheFactory/newspaper4k/compare/0.9.4...0.9.5
- 0.9.4.1Version 0.9.4.1 - Python 3.14 support2025-11-18 · 2025-11-18 06:08 UTC
查看更新说明
- feat: add support for python 3.14
- rework: minor typing changes
- tests: increase test coverage
What's Changed
- lang: Add Kurdish Kurmanji stop words by @cikay in https://github.com/AndyTheFactory/newspaper4k/pull/677
- docs: Update supported languages by @cikay in https://github.com/AndyTheFactory/newspaper4k/pull/676
- docs: bump sphinx version by @AndyTheFactory in https://github.com/AndyTheFactory/newspaper4k/pull/680
- Docs 0.9.4 by @AndyTheFactory in https://github.com/AndyTheFactory/newspaper4k/pull/681
New Contributors
- @cikay made their first contribution in https://github.com/AndyTheFactory/newspaper4k/pull/677
Full Changelog: https://github.com/AndyTheFactory/newspaper4k/compare/0.9.4...0.9.4.1
- 0.9.4Version 0.9.4 - Dropping python 3.8, 3.9, Switching to `uv`, improving tests2025-11-15 · 2025-11-15 21:52 UTC
查看更新说明
New Features
Bumped min Python version to 3.10. Version 3.8 and 3.9 are no longer supported, but might still work.
- misc: switch to uv from poetry
- parse: add brotli compression
- install: dependency versions pin
- tests: split tests into unit, integration and e2e. Only unit tests are ran on each PR. Integration and e2e tests are ran locally when developing.
- tests: added coverage report generation. Coverage uploaded to coveralls.io
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Newspaper4k: Article Scraping & Curation, a continuation of the beloved newspaper3k by codelucas
Newspaper4k Project grew from a fork of the well known newspaper3k by codelucas which was not updated since September 2020. The initial goal of this fork was to keep the project alive and to add new features and fix bugs. As of version 0.9.3 there are many new features and improvements that make Newspaper4k a great tool for article scraping and curation. To make the migration to Newspaper4k easier, all the classes and methods from the original project were kept and the new features were added on top of them. All API calls from the original project still work as expected, such that for users familiar with newspaper3k you will feel right at home with Newspaper4k.
At the moment of the fork, in the original project were over 400 open issues, which I have duplicated, and as of v 0.9.3 only about 180 issues still need to be verified (many are already fixed, but it's pretty cumbersome to check - hint hint ... anyone contributing?). If you have any issues or feature requests please open an issue here.
| Experimental ChatGPT helper bot for Newspaper4k: | ![]() |
Python compatibility
- Python 3.10+ minimum
Quick start
pip install newspaper4k
Using the CLI
You can start directly from the command line, using the included CLI:
python -m newspaper --url="https://edition.cnn.com/2023/11/17/success/job-seekers-use-ai/index.html" --language=en --output-format=json --output-file=article.json
More information about the CLI can be found in the CLI documentation.

Using the Python API
Alternatively, you can use Newspaper4k in Python:
Processing one article / url at a time
import newspaper
article = newspaper.article('https://edition.cnn.com/2023/10/29/sport/nfl-week-8-how-to-watch-spt-intl/index.html')
print(article.authors)
# ['Hannah Brewitt']
print(article.publish_date)
# 2023-10-29 09:00:15.717000+00:00
print(article.text)
# New England Patriots head coach Bill Belichick, right, embraces Buffalo Bills head coach Sean McDermott ...
print(article.top_image)
# https://media.cnn.com/api/v1/images/stellar/prod/231015223702-06-nfl-season-gallery-1015.jpg?c=16x9&q=w_800,c_fill
print(article.movies)
# []
article.nlp()
print(article.keywords)
# ['patrick', 'mahomes', 'history', 'nfl', 'week', 'broncos', 'denver', 'p', 'm', '00', 'pittsburgh',...]
print(article.summary)
# Kevin Sabitus/Getty Images Denver Broncos running back Javonte Williams evades Green Bay Packers safety Darnell Savage, bottom.
# Kathryn Riley/Getty Images Kansas City Chiefs quarterback Patrick Mahomes calls a play during the Chiefs' 19-8 Thursday Night Football win over the Denver Broncos on October 12.
# Paul Sancya/AP New York Jets running back Breece Hall carries the ball during a game against the Denver Broncos.
# The Broncos have not beaten the Chiefs since 2015, and have never beaten Chiefs quarterback Patrick Mahomes.
# Australia: NFL+, ESPN, 7Plus Brazil: NFL+, ESPN Canada: NFL+, CTV, TSN, RDS Germany: NFL+, ProSieben MAXX, DAZN Mexico: NFL+, TUDN, ESPN, Fox Sports, Sky Sports UK: NFL+, Sky Sports, ITV, Channel 5 US: NFL+, CBS, NBC, FOX, ESPN, Amazon Prime

Parsing and scraping whole News Sources (websites) using the Source Class
This way you can build a Source object from a newspaper websites. This class will allow you to get all the articles and categories on the website. When you build the source, articles are not yet downloaded. The build() call will parse front page, will detect category links (if possible), get any RSS feeds published by the news site, and will create a list of article links.
You need to call download_articles() to download the articles, but note that it can take a significant time.
download_articles() will download the articles in a multithreaded fashion using ThreadPoolExecutor from the concurrent package. The number of concurrent threads can be configured in Configuration.number_threads or passed as an argument to build().
import newspaper
cnn_paper = newspaper.build('http://cnn.com', number_threads=3)
print(cnn_paper.category_urls())
# ['https://cnn.com', 'https://money.cnn.com', 'https://arabic.cnn.com',
# 'https://cnnespanol.cnn.com', 'http://edition.cnn.com',
# 'https://edition.cnn.com', 'https://us.cnn.com', 'https://www.cnn.com']
article_urls = [article.url for article in cnn_paper.articles]
print(article_urls[:3])
# ['https://arabic.cnn.com/middle-east/article/2023/10/30/number-of-hostages-held-in-gaza-now-up-to-239-idf-spokesperson',
# 'https://arabic.cnn.com/middle-east/video/2023/10/30/v146619-sotu-sullivan-hostage-negotiations',
# 'https://arabic.cnn.com/middle-east/article/2023/10/29/norwegian-pm-israel-gaza']
article = cnn_paper.articles[0]
article.download()
article.parse()
print(article.title)
# المتحدث باسم الجيش الإسرائيلي: عدد الرهائن المحتجزين في غزة يصل إلى
Or if you want to get bulk articles from the website (have in mind that this could take a long time and could get your IP blocked by the newssite):
import newspaper
cnn_source = newspaper.build('http://cnn.com', number_threads=3)
print(len(newspaper.article_urls))
articles = source.download_articles()
print(len(articles))
print(articles[0].title)
As of version 0.9.3, Newspaper4k supports Google News as a special Source object
First, make sure you have the google extra installed, since we rely on the Gnews package to get the articles from Google News. You can install it using pip like this:
pip install newspaper4k[gnews]
Then you can use the GoogleNews class to get articles from Google News:
from newspaper.google_news import GoogleNewsSource
source = GoogleNewsSource(
country="US",
period="7d",
max_results=10,
)
source.build(top_news=True)
print(source.article_urls())
# ['https://www.cnn.com/2024/03/18/politics/trump-464-million-dollar-bond/index.html', 'https://www.cnn.com/2024/03/18/politics/supreme-court-new-york-nra/index.html', ...
source.download_articles()
Multilanguage features
Newspaper can extract and detect languages seamlessly based on the article meta tags. Additionally, you can specify the language for the website / article. If no language is specified, Newspaper will attempt to auto detect a language from the available meta data. The fallback language is English.
Language detection is crucial for accurate article extraction. If the wrong language is detected or provided, chances are that no article text will be returned. Before parsing, check that your language is supported by our package.
from newspaper import Article
article = Article('https://www.bbc.com/zhongwen/simp/chinese-news-67084358')
article.download()
article.parse()
print(article.title)
# 晶片大战:台湾厂商助攻华为突破美国封锁?
if article.config.use_meta_language:
# If we use the autodetected language, this config attribute will be true
print(article.meta_lang)
else:
print(article.config.language)
# zh
Docs
Check out The Docs for full and detailed guides using newspaper.
Features
- Multi-threaded article download framework
- Newspaper website category structure detection
- News url identification
- Google News integration
- Text extraction from html
- Top image extraction from html
- All image extraction from html
- Keyword building from the extracted text
- Automatic article text summarization
- Author extraction from text
- Easy to use Command Line Interface (
python -m newspaper....) - Output in various formats (json, csv, text)
- Works in 80+ languages (English, Chinese, German, Arabic, ...) see LANGUAGES.md for the full list of supported languages.
Evaluation
Evaluation Results
Using the dataset from ScrapingHub I created an evaluator script that compares the performance of newspaper against it's previous versions. This way we can see how newspaper updates improve or worsen the performance of the library.
| Version | Corpus BLEU Score | Corpus Precision Score | Corpus Recall Score | Corpus F1 Score |
|---|---|---|---|---|
| Newspaper3k 0.2.8 | 0.8660 | 0.9128 | 0.9071 | 0.9100 |
| Newspaper4k 0.9.0 | 0.9212 | 0.8992 | 0.9336 | 0.9161 |
| Newspaper4k 0.9.1 | 0.9224 | 0.8895 | 0.9242 | 0.9065 |
| Newspaper4k 0.9.2 | 0.9426 | 0.9070 | 0.9087 | 0.9078 |
| Newspaper4k 0.9.3 | 0.9531 | 0.9585 | 0.9339 | 0.9460 |
| Newspaper4k 0.9.4 | 0.9531 | 0.9585 | 0.9339 | 0.9460 |
| Newspaper4k 0.9.5 | 0.9531 | 0.9585 | 0.9339 | 0.9460 |
| Newspaper4k 0.9.6 | 0.9531 | 0.9585 | 0.9339 | 0.9460 |
Precision, Recall and F1 are computed using overlap of shingles with n-grams of size 4. The corpus BLEU score is computed using the nltk's bleu_score.
We also use our own, newly created dataset, the Newspaper Article Extraction Benchmark (NAEB) which is a collection of over 400 articles from 200 different news sources to evaluate the performance of the library.
| Version | Corpus BLEU Score | Corpus Precision Score | Corpus Recall Score | Corpus F1 Score |
|---|---|---|---|---|
| Newspaper3k 0.2.8 | 0.8445 | 0.8760 | 0.8556 | 0.8657 |
| Newspaper4k 0.9.0 | 0.8357 | 0.8547 | 0.8909 | 0.8724 |
| Newspaper4k 0.9.1 | 0.8373 | 0.8505 | 0.8867 | 0.8682 |
| Newspaper4k 0.9.2 | 0.8422 | 0.8888 | 0.9240 | 0.9061 |
| Newspaper4k 0.9.3 | 0.8695 | 0.9140 | 0.8921 | 0.9029 |
| Newspaper4k 0.9.4 | 0.8689 | 0.9140 | 0.8921 | 0.9029 |
| Newspaper4k 0.9.5 | 0.8689 | 0.9140 | 0.8921 | 0.9029 |
| Newspaper4k 0.9.6 | 0.8696 | 0.9136 | 0.8898 | 0.9015 |
Requirements and dependencies
The package has two kinds of requirements:
- System libraries (needed for
lxmland image support) - Python package dependencies (installed via
pipor a pinnedrequirements.txt)
System packages (common)
- Pillow:
libjpeg-dev,zlib1g-dev,libpng-dev(orlibpng12-devon older systems) - lxml:
libxml2-dev,libxslt1-dev - Python development headers:
python3-dev
Debian / Ubuntu (install prerequisites):
sudo apt-get install python3 python3-dev python3-pip libxml2-dev libxslt1-dev libjpeg-dev zlib1g-dev libpng-dev
macOS (Homebrew):
brew install libxml2 libxslt
brew install libtiff libjpeg webp little-cms2
Installing the package (pip)
Basic install:
pip install newspaper4k
Optional extras
Newspaper4k exposes several optional extras that enable additional features:
gnews— Google News integration (gnewspackage)nlp— NLP helpers (e.g.nltk)cloudflare—cloudscraperfor Cloudflare-protected siteszh,th,ja,bn,hi,np,ta- language-specific NLP support (e.g.jiebafor Chinese)all— a convenience extra that installs many language and helper packages
Examples:
pip install newspaper4k[gnews]
pip install "newspaper4k[gnews,nlp]"
pip install newspaper4k[all]
Use whichever extras you need; extras can be combined as shown above.
Install using uv (recommended for reproducible, pinned installs)
uv can generate a pinned requirements.txt from pyproject.toml which is
handy for deployments or for reproducible installs.
-
Install
uv(if you don't have it):pip install uv -
add the newspaper4k package to your project using
uv add(you must be in a project directory with apyproject.tomlfile):uv add newspaper4k
or if you want to include extras:
uv add --all-groups newspaper4k
or uv add --group gnews newspaper4k
Notes
- If you encounter problems with
libpng12-dev, trylibpng-devinstead. - The optional extras are declared in
pyproject.tomlunder[project.optional-dependencies](for examplegnews,nlp,cloudflare,all).
Contributing
see CONTRIBUTING.md
LICENSE
Authored and maintained by Andrei Paraschiv.
Newspaper was originally developed by Lucas Ou-Yang (codelucas), the original repository can be found here. Newspaper is licensed under the MIT license.
Credits
Thanks to Lucas Ou-Yang for creating the original Newspaper3k project and to all contributors of the original project.
