Created
April 25, 2018 15:50
-
-
Save canwe/12b1c4555481c141bfccb3c59b4c40ee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- 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