#TSMC
import requests
#TSMC
#site = "https://query1.finance.yahoo.com/v7/finance/download/2330.TW?period1=0&period2=1585008000&interval=1d&events=history&crumb=hP2rOschxO0"
site = "https://query1.finance.yahoo.com/v7/finance/download/goog?period1=0&period2=1585008000&interval=1d&events=history&crumb=hP2rOschxO0"
response = requests.get(site)
print(response.text)
import requests
import datetime
start = int(datetime.datetime(2000, 1, 1).timestamp())
end = int(datetime.datetime(2020, 3, 24).timestamp())
site = "https://query1.finance.yahoo.com/v7/finance/download/goog?period1=" + str(start) + "&period2=" + str(end) + "&interval=1d&events=history&crumb=hP2rOschxO0"
#print(site)
#site = "https://query1.finance.yahoo.com/v7/finance/download/goog?period1=0&period2=1585008000&interval=1d&events=history&crumb=hP2rOschxO0"
response = requests.get(site)
with open('file.csv', 'w') as f:
f.writelines(response.text)
import pandas as pd
df = pd.read_csv('file.csv')
輸出結果
Date,Open,High,Low,Close,Adj Close,Volume2004-08-19,49.813286,51.835709,47.800831,49.982655,49.982655,448713002004-08-20,50.316402,54.336334,50.062355,53.952770,53.952770,229428002004-08-23,55.168217,56.528118,54.321388,54.495735,54.495735,183428002004-08-24,55.412300,55.591629,51.591621,52.239193,52.239193,153197002004-08-25,52.284027,53.798351,51.746044,52.802086,52.802086,92321002004-08-26,52.279045,53.773445,52.134586,53.753517,53.753517,71286002004-08-27,53.848164,54.107193,52.647663,52.876804,52.876804,62412002004-08-30,52.443428,52.548038,50.814533,50.814533,50.814533,52214002004-08-31,50.958992,51.661362,50.889256,50.993862,50.993862,49412002004-09-01,51.158245,51.292744,49.648903,49.937820,49.937820,91816002004-09-02,49.409801,50.993862,49.285267,50.565468,50.565468,15190400:with open('file.csv', 'w') as f:
f.writelines(response.text)
import pandas as pd
df = pd.read_csv('file.csv')
df
輸出結果
Date Open High Low Close Adj Close Volume0 2004-08-19 49.813286 51.835709 47.800831 49.982655 49.982655 448713001 2004-08-20 50.316402 54.336334 50.062355 53.952770 53.952770 229428002 2004-08-23 55.168217 56.528118 54.321388 54.495735 54.495735 183428003 2004-08-24 55.412300 55.591629 51.591621 52.239193 52.239193 153197004 2004-08-25 52.284027 53.798351 51.746044 52.802086 52.802086 9232100.%matplotlib inline
df.Close.plot()
輸出結果
輸出結果