Newspaper3k: Article scraping & curation ======================================== .. image:: https://badge.fury.io/py/newspaper3k.svg :target: http://badge.fury.io/py/newspaper3k.svg :alt: Latest version .. image:: https://travis-ci.org/codelucas/newspaper.svg :target: http://travis-ci.org/codelucas/newspaper/ :alt: Build status .. image:: https://coveralls.io/repos/github/codelucas/newspaper/badge.svg?branch=master :target: https://coveralls.io/github/codelucas/newspaper :alt: Coverage status Inspired by `requests`_ for its simplicity and powered by `lxml`_ for its speed: "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`_ .. _`tweeted by`: https://twitter.com/kennethreitz/status/419520678862548992 .. _`The Changelog`: http://thechangelog.com/newspaper-delivers-instapaper-style-article-extraction/ **Newspaper is a Python3 library**! Or, view our **deprecated and buggy** `Python2 branch`_ .. _`Python2 branch`: https://github.com/codelucas/newspaper/tree/python-2-head A Glance: --------- .. code-block:: pycon >>> from newspaper import Article >>> url = 'http://fox13now.com/2013/12/30/new-year-new-laws-obamacare-pot-guns-and-drones/' >>> article = Article(url) .. code-block:: pycon >>> article.download() >>> article.html '`_. Use code ``PROXY90`` for 10% off your first plan. .. _`Swiftproxy`: https://www.swiftproxy.net/?ref=codelucas Docs ---- Check out `The Docs`_ for full and detailed guides using newspaper. Interested in adding a new language for us? Refer to: `Docs - Adding new languages `_ Features -------- - 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 - Works in 10+ languages (English, Chinese, German, Arabic, ...) .. code-block:: pycon >>> import newspaper >>> newspaper.languages() Your available languages are: input code full name ar Arabic be Belarusian bg Bulgarian da Danish de German el Greek en English es Spanish et Estonian fa Persian fi Finnish fr French he Hebrew hi Hindi hr Croatian hu Hungarian id Indonesian it Italian ja Japanese ko Korean lt Lithuanian mk Macedonian nb Norwegian (Bokmål) nl Dutch no Norwegian pl Polish pt Portuguese ro Romanian ru Russian sl Slovenian sr Serbian sv Swedish sw Swahili th Thai tr Turkish uk Ukrainian vi Vietnamese zh Chinese Get it now ---------- Run ✅ ``pip3 install newspaper3k`` ✅ NOT ⛔ ``pip3 install newspaper`` ⛔ On python3 you must install ``newspaper3k``, **not** ``newspaper``. ``newspaper`` is our python2 library. Although installing newspaper is simple with `pip `_, you will run into fixable issues if you are trying to install on ubuntu. **If you are on Debian / Ubuntu**, install using the following: - Install ``pip3`` command needed to install ``newspaper3k`` package:: $ sudo apt-get install python3-pip - Python development version, needed for Python.h:: $ sudo apt-get install python-dev - lxml requirements:: $ sudo apt-get install libxml2-dev libxslt-dev - For PIL to recognize .jpg images:: $ sudo apt-get install libjpeg-dev zlib1g-dev libpng12-dev NOTE: If you find problem installing ``libpng12-dev``, try installing ``libpng-dev``. - Download NLP related corpora:: $ curl https://raw.githubusercontent.com/codelucas/newspaper/master/download_corpora.py | python3 - Install the distribution via pip:: $ pip3 install newspaper3k **If you are on OSX**, install using the following, you may use both homebrew or 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 **Otherwise**, install with the following: NOTE: You will still most likely need to install the following libraries via your package manager - PIL: ``libjpeg-dev`` ``zlib1g-dev`` ``libpng12-dev`` - lxml: ``libxml2-dev`` ``libxslt-dev`` - Python Development version: ``python-dev`` :: $ pip3 install newspaper3k $ curl https://raw.githubusercontent.com/codelucas/newspaper/master/download_corpora.py | python3 Development ----------- If you'd like to contribute and hack on the newspaper project, feel free to clone a development version of this repository locally:: git clone git://github.com/codelucas/newspaper.git Once you have a copy of the source, you can embed it in your Python package, or install it into your site-packages easily:: $ pip3 install -r requirements.txt $ python3 setup.py install Feel free to give our testing suite a shot, everything is mocked!:: $ python3 tests/unit_tests.py Planning on tweaking our full-text algorithm? Add the ``fulltext`` parameter:: $ python3 tests/unit_tests.py fulltext Demo ---- View a working online demo here: http://newspaper-demo.herokuapp.com This is another working online demo: http://newspaper.chinazt.cc/ Scraping the local edition of any news site =========================================== News sites don't serve everyone the same page. Front pages are localized by country, some stories are geo-restricted, and EU visitors often get a consent wall before they ever see an article. If your scraper always runs from one server, that server's edition is the only one you'll ever collect. `Decodo`_ lets you pick where every request comes from — residential IPs in 195+ locations, targetable by country, state, city, ZIP code, or ASN — so newspaper3k gets exactly the page a local reader would. Generate a proxy string per location in the Decodo dashboard (*Residential → Proxy setup*), then give each edition its own ``config``: .. code-block:: python import newspaper from newspaper import Config # one proxy string per location, generated in the Decodo dashboard EDITIONS = { 'us': 'http://US_USERNAME:PASSWORD@gate.decodo.com:7000', 'gb': 'http://GB_USERNAME:PASSWORD@gate.decodo.com:7000', 'de': 'http://DE_USERNAME:PASSWORD@gate.decodo.com:7000', } for country, proxy in EDITIONS.items(): config = Config() config.proxies = {'http': proxy, 'https': proxy} config.request_timeout = 20 paper = newspaper.build('https://www.bbc.com', config=config, memoize_articles=False) print(f'[{country}] {paper.size()} articles') for article in paper.articles[:5]: article.download() article.parse() print(' ', article.title) ``newspaper.build()`` hits the homepage, category pages, and feeds before a single article downloads. If a site sets cookies or consent state on that first visit, choose a sticky session when generating the proxy string: Decodo holds the same IP for up to 30 minutes, so the whole crawl looks like one reader browsing rather than a new stranger on every request. Get credentials and a 3-day, 100MB trial at `decodo.com `_. .. _`Decodo`: https://visit.decodo.com/DWGVM2 Interested in scraping APIs & proxies? ====================================== Scrape every news site the way local readers see it --------------------------------------------------- .. image:: https://github.com/user-attachments/assets/0bbe6359-7b5b-4a7f-9ace-c6034ecac572 :target: https://visit.decodo.com/DWGVM2 :alt: Decodo — residential proxies with exact location targeting across 195+ locations. `Try Decodo`_ — run high-volume automated requests through reliable residential IPs in 195+ locations. Get exact location data on demand, down to the country, city, ZIP code, or ASN, with unbroken connection stability and total request privacy. 115M+ ethically-sourced IPs, 99.99% uptime, unlimited concurrent sessions, and your choice of rotating IPs or sticky sessions of up to 30 minutes. Start with a 3-day, 100MB trial. .. _`Try Decodo`: https://visit.decodo.com/DWGVM2 Power your scraping and automation at real-world scale ------------------------------------------------------ `Click here to try Swiftproxy`_ — built for developers running scraping, automation, and data collection workflows at scale. Access 80M+ residential IPs from $0.7/GB, fast ISP proxies from $6/IP, global coverage across 195+ countries, non-expiring traffic, and a 99.89% success rate. Free trial available — use code ``PROXY90`` for 10% off. .. image:: https://github.com/user-attachments/assets/913f1fd6-20e9-4f37-89b7-ba6b0bd0724a :target: https://www.swiftproxy.net/?ref=codelucas :alt: Swiftproxy — residential and ISP proxies built for scrapers and developers. .. _`Click here to try Swiftproxy`: https://www.swiftproxy.net/?ref=codelucas Unlock the Web — the Smart Way ------------------------------ `Click here to see SerpApi, scrape search engines easily with SerpApi - Search API`_. Scrape Google Search, Google News, Google Maps, and more! .. image:: https://github.com/user-attachments/assets/9a80eeb4-72a8-43f1-9413-93c7a47b2bf6 :target: https://serpapi.com/google-news-api?utm_source=newspaper3k_github :alt: Scrape search engines easily with SerpApi - Search API. .. _`Click here to see SerpApi, scrape search engines easily with SerpApi - Search API`: https://serpapi.com?utm_source=newspaper3k_github Stay private, fast, and fully in control ---------------------------------------- `Click here to explore BestProxy`_, your go-to solution for premium residential proxies. BestProxy's proxies ensure smooth browsing, fast speeds, and total anonymity. `Get Started`_ today and experience the difference! .. image:: https://github.com/user-attachments/assets/1c6ef38c-f0c0-4db0-aad2-3ed9d6adf0b5 :target: https://bestproxy.com/?keyword=b2vgzl0r :alt: Experience BestProxy, smooth browsing, fast speeds, and total anonymity. .. _`Click here to explore BestProxy`: https://bestproxy.com/?keyword=b2vgzl0r .. _`Get Started`: https://bestproxy.com/?keyword=b2vgzl0r LICENSE ------- Authored and maintained by `Lucas Ou-Yang`_. `Parse.ly`_ sponsored some work on newspaper, specifically focused on automatic extraction. Newspaper uses a lot of `python-goose's`_ parsing code. View their license `here`_. Please feel free to `email & contact me`_ if you run into issues or just would like to talk about the future of this library and news extraction in general! .. _`Lucas Ou-Yang`: http://codelucas.com .. _`email & contact me`: mailto:lucasyangpersonal@gmail.com .. _`python-goose's`: https://github.com/grangier/python-goose .. _`here`: https://github.com/codelucas/newspaper/blob/master/GOOSE-LICENSE.txt .. _`https://www.paypal.me/codelucas`: https://www.paypal.me/codelucas .. _`Venmo`: https://www.venmo.com/Lucas-Ou-Yang .. _`Quickstart guide`: https://newspaper.readthedocs.io/en/latest/ .. _`The Docs`: https://newspaper.readthedocs.io .. _`lxml`: http://lxml.de/ .. _`requests`: https://github.com/kennethreitz/requests .. _`Parse.ly`: http://parse.ly .. _`It takes only one click`: https://tracking.gitads.io/?campaign=gitads&repo=newspaper&redirect=gitads.io Impact-Site-Verification: 49caf271-823a-450f-84fe-2cc756c8391b