Skip to content

Instantly share code, notes, and snippets.

@klenwell
Created June 25, 2015 13:44
Show Gist options
  • Save klenwell/9e5eb216d5d2d7e9bdfb to your computer and use it in GitHub Desktop.
Save klenwell/9e5eb216d5d2d7e9bdfb to your computer and use it in GitHub Desktop.
Simple Scraper for Dow Jones Industrial Average
#
# Simple Scraper for Dow Jones Industrial Average
# With Python 3
#
# INSTALLATION (with pyenv)
# pyenv local 3.4.1
# pip install requests
# pip install beautifulsoup4
# pip install https://github.com/syabro/soupselect/archive/master.zip
#
# USAGE
# python ./djia.py
#
from bs4 import BeautifulSoup as Soup
from soupselect import select as css_select
import requests
#
# Yahoo Example
#
yahoo_url = "http://finance.yahoo.com/q?s=^DJI"
html = requests.get(yahoo_url).content
soup = Soup(html)
djia_open = css_select(soup, 'div#yfi_quote_summary_data td.yfnc_tabledata1')
print('Yahoo DJIA open: %s' % djia_open[0].text)
djia_current = css_select(soup, 'span#yfs_l10_^dji')
print('Yahoo DJIA current: %s' % djia_current[0].text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment