Skip to main content

Simple script to scrape polling data from RealClearPolitics and output as .csv

Project description

Python client for RealClearPolitics.

Install

pip install realclearpolitics

Usage

usage: rcp [-h] [--output [OUTPUT]] url [url ...]

positional arguments:
  url                The url of the polling data.

optional arguments:
  -h, --help         show this help message and exit
  --output [OUTPUT]  The output file name.

Examples

Get the US general election results.

rcp http://www.realclearpolitics.com/epolls/2016/president/us/general_election_trump_vs_clinton-5491.html --output general.csv

Download multiple polls.

rcp http://www.realclearpolitics.com/epolls/2016/president/us/general_election_trump_vs_clinton-5491.html \
> https://www.realclearpolitics.com/epolls/other/president_trump_job_approval_economy-6182.html \
> https://www.realclearpolitics.com/epolls/other/president_trump_job_approval_foreign_policy-6183.html

API Usage

Search for Fox News poll numbers for Trump:

from rcp import get_polls, get_poll_data
from pprint import pprint

polls = get_polls(q="Trump", p="Fox")

for poll in polls:
    td = get_poll_data(poll['url'])
    pprint(td)

The will return a dictionary structured like this:

[
    {
        'data': [{'Biden (D)': '49.6',
                'Date': '3/27 - 7/9',
                'MoE': '--',
                'Poll': 'RCP Average',
                'Sample': '--',
                'Spread': 'Biden +8.5',
                'Trump (R)': '41.1'},
        ...
        }],
    'poll': 'https://www.realclearpolitics.com/epolls/2020/president/us/general_election_trump_vs_biden-6247.html'

]

Write a poll to CSV:

from rcp import get_polls, get_poll_data, to_csv

polls = get_polls(q="Biden")[0]
data = get_poll_data(polls['url'])
to_csv('output.csv', data)

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

realclearpolitics-1.2.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

realclearpolitics-1.2.0-py2.py3-none-any.whl (4.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file realclearpolitics-1.2.0.tar.gz.

File metadata

  • Download URL: realclearpolitics-1.2.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for realclearpolitics-1.2.0.tar.gz
Algorithm Hash digest
SHA256 806f196f0c11b9d998e8f404d3277c4ba2b56962af94ab2691a7c041a4b7424b
MD5 a8424a292c3cd5d511696f7306a71b1b
BLAKE2b-256 7100c3d3dac424b52a5cf1912b805b41d706d6a79414802d51db454c67fb6f07

See more details on using hashes here.

File details

Details for the file realclearpolitics-1.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: realclearpolitics-1.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for realclearpolitics-1.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0f3cb90dfd80fee06fc51697c56e5365556653fef56fe57d48517f4fa5024064
MD5 0025a8f6602922b82b3d8d2aa176345c
BLAKE2b-256 88fe7a46844066708238e022aa67af194e064c5ca48a8b988f33563dc766ba9b

See more details on using hashes here.

Supported by

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