Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Top News Selectors (tns): Top news parsing from select websites

Project Description

# Top-news-selectors (tns)

A static HTML site parser for parsing the top story titles and URIs for the following websites:

This parser is built on [Beautifulsoup4]( based on the CSS selectors found inside the respective HTML documents. These selectors were chosen based on the selectors that were present during the 30 days for the month of November 2016.

This package has not been tested beyond the month of November 2016, 11/01/2016 - 11/30/2016. Use at your own risk when going beyond that range.

## Install

This package is available via pip:

` $ pip install tns `

## Usage

`python >>> from tns import SiteParser >>> html = open('npr.html').read() >>> parser = SiteParser(html) >>> parser.npr() { 'hero_text': "foo", 'hero_link': '', 'headlines': [{'splash_title': 'baz', 'link': ''}] } >>> parser.washingtonpost() {'hero_text': '', 'hero_link': '', 'headlines': []} `

The keys hero_text and hero_link refer to the top most identified news post, often identified by a enlarged picture or text across the top of the page. Headlines refer to the subsequent headlines after the hero article, where splash_title refers to the title found on the home page of the site not the actual title of the article.

You can see that the second function call with parser, parser.washingtonpost(), has zero entries because the document passed to SiteParser was not intended for that parser.

Each of the sites are paired to a function:

`python "":          parser.abcnews() "":        parser.cbsnews() "":        parser.nbcnews() "": parser.washingtonpost() "":            parser.npr() "":         parser.latimes() "":       parser.usatoday() "":            parser.wsj() "":        parser.nytimes() "":          parser.foxnews() "":  parser.chicagotribune() `

## Debugging

When the parser fails to find specific headlines or returns no headlines at all, this could be due to:

  • Iframes loading content dynamically
  • Headlines being injected via Javascript
  • The wrong parser is being used for the specified site

Release History

This version
History Node


Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(7.4 kB) Copy SHA256 Hash SHA256
Wheel py3 Feb 4, 2018
(5.3 kB) Copy SHA256 Hash SHA256
Source None Feb 4, 2018

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Kabu Creative Kabu Creative UX & Design Google Google Cloud Servers Fastly Fastly CDN StatusPage StatusPage Statuspage DigiCert DigiCert EV Certificate