url="https://www.twse.com.tw/exchangeReport/STOCK_DAY?response=json&date=20220330&stockNo=2330"
print('練習股票爬蟲')
import numpy as np
import requests
import matplotlib.pyplot as plt
for i in range(50):
r=requests.get('https://eclass.uch.edu.tw/media/40004/')
print(i, r.status_code)
url="https://www.twse.com.tw/exchangeReport/STOCK_DAY?response=json&date=20241031&stockNo=2330"
data=requests.get(url)
data.text
jsonTxt=data.json()
jsonTxt
xx=jsonTxt['data']
price=[]
days=[]
for x in xx:
print(x[0],'-->', x[6])
_, _,day=x[0].split('/')
days.append(int(day))
x[6]=x[6].replace(',', '')
price.append(float(x[6]))
plt.bar(days,price)
plt.xlim([1,31.5])
plt.show()
plt.plot(days,price, 'r-')
plt.xlim([1,30])
plt.show()
1 則留言:
股價超過1000會有','
請多加一行指令
x[6]=x[6].replace(',', '')
張貼留言