Skip to content

Instantly share code, notes, and snippets.

@klenwell klenwell/djia.py
Created Jun 25, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.