Skip to main content

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](https://www.crummy.com/software/BeautifulSoup/bs4/doc/) 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': 'http://bar.com', 'headlines': [{'splash_title': 'baz', 'link': 'http://qux.com'}] } >>> 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 "http://abcnews.go.com/": parser.abcnews() "https://www.cbsnews.com/": parser.cbsnews() "https://www.nbcnews.com/": parser.nbcnews() "https://www.washingtonpost.com/": parser.washingtonpost() "https://www.npr.org/": parser.npr() "http://www.latimes.com/": parser.latimes() "https://www.usatoday.com/": parser.usatoday() "https://www.wsj.com/": parser.wsj() "https://www.nytimes.com/": parser.nytimes() "http://www.foxnews.com": parser.foxnews() "http://www.chicagotribune.com/": 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

Project details


Download files

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

Source Distribution

tns-1.0.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tns-1.0.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file tns-1.0.0.tar.gz.

File metadata

  • Download URL: tns-1.0.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for tns-1.0.0.tar.gz
Algorithm Hash digest
SHA256 7bd90549e71231a95675b2d76760bfc43ca9fb4b335fd762db8ddef17a51f4c9
MD5 c7f5d5691175ec6e40bf86126a1616fd
BLAKE2b-256 36a8d19acc83571840969a39fb8e18c1f8b444755bbebd7afb81c191d0787228

See more details on using hashes here.

File details

Details for the file tns-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: tns-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for tns-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a745237ef5a5662af7b9d3e0299a81c36afaeb85718982a8bec1b67c01cec0bf
MD5 8229415658d549f3377dfd0acc435867
BLAKE2b-256 766164cc2486f92de0051560147b8df7b2b8ec4469e72096b6c9476a4419d788

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page