如何取得每日的股價資訊
進入證交所每日收盤行情,選擇全部(不含…),可以看到有許多選項可點。
找到每日收盤行情
點擊F12進入開發者環境,再點選Network,觀察我們要的數據資訊
import requests
url = "https://www.twse.com.tw/exchangeReport/MI_INDEX?response=json&date=20210827&type=ALLBUT0999&_=1630244648174"
res = requests.get(url)
res.json()
得到Json,並在data9找到全部的股票數據
{'alignsStyle1': [['center', 'center', 'center', 'center', 'center', 'center'],
...
...
'data9': [['0050',
'元大台灣50',
'16,875,047',
'9,673',
'2,328,482,421',
'136.70',
'138.50',
'136.45',
'138.15',
'<p style= color:red>+</p>',
'1.15',
'138.15',
'4',
'138.20',
'103',
'0.00'],
['0051',
'元大中型100',
'17,810',
'63',
'1,003,448',
'56.20',
'56.60',
'56.20',
'56.60',
'<p style= color:red>+</p>',
'0.35',
'56.55',
'1',
'56.60',
'9',
'0.00'],
...
...
'subtitle9': '110年08月27日每日收盤行情(全部(不含權證、牛熊證))'}
幾個重要的數據
['0050', #股票代號
'元大台灣50',
'16,875,047', #成交股數
'9,673',
'2,328,482,421',
'136.70', #開盤價
'138.50', #最高價
'136.45', #最低價
'138.15', #收盤價
'<p style= color:red>+</p>',
'1.15',
'138.15',
'4',
'138.20',
'103',
'0.00'],
輕鬆完成,在爬取過程中還是非常簡單的,
不用進行太多的偽裝和Headers,
再來就是要儲存資料和處理成Function。
有甚麼問題歡迎一起討論~
Python 爬取每日股價(1) 有 “ 1 則迴響 ”