Skip to content

Instantly share code, notes, and snippets.

@canwe
Created April 25, 2018 15:51
Show Gist options
  • Save canwe/6ad0247286e184cde7be8ac32df940e1 to your computer and use it in GitHub Desktop.
Save canwe/6ad0247286e184cde7be8ac32df940e1 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
"""
Get djidf
@author: Dazhuang
"""
import requests
import re
import pandas as pd
def retrieve_dji_list():
r = requests.get('http://money.cnn.com/data/dow30/')
search_pattern = re.compile('class="wsod_symbol">(.*?)<\/a>.*<span.*">(.*)<\/span>.*\n.*class="wsod_stream">(.*)<\/span>')
dji_list_in_text = re.findall(search_pattern, r.text)
dji_list = []
for item in dji_list_in_text:
dji_list.append([item[0], item[1], float(item[2])])
return dji_list
dji_list = retrieve_dji_list()
djidf = pd.DataFrame(dji_list)
cols = ['code', 'name', 'lasttrade']
djidf.columns = cols
print(djidf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment