Skip to content

Instantly share code, notes, and snippets.

@canwe
Created April 25, 2018 15:50
Show Gist options
  • Save canwe/12b1c4555481c141bfccb3c59b4c40ee to your computer and use it in GitHub Desktop.
Save canwe/12b1c4555481c141bfccb3c59b4c40ee to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
"""
Get quotesdf
@author: Dazhuang
"""
import requests
import re
import json
import pandas as pd
def retrieve_quotes_historical(stock_code):
quotes = []
url = 'https://finance.yahoo.com/quote/%s/history?p=%s' % (stock_code, stock_code)
r = requests.get(url)
m = re.findall('"HistoricalPriceStore":{"prices":(.*?),"isPending"', r.text)
if m:
quotes = json.loads(m[0])
quotes = quotes[::-1]
return [item for item in quotes if not 'type' in item]
quotes = retrieve_quotes_historical('AXP')
quotesdf = pd.DataFrame(quotes)
print(quotesdf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment