[問題] 如何抓取上市股票交易明細
各位好,小弟為python新手,想要利用python取得上市櫃股票的交易明細並分析
成交量或是成交價的變化。
下面是我針對上櫃某些股票的code,打算利用電腦排程每日確認成交價/量變化
# -*- coding: utf-8 -*-
import pandas as pd
from pandas import Series, DataFrame
#抓取最近兩個月的成交明細並合併成一個DF
def get_id(idnum):
df=pd.read_html("http://www.tpex.org.tw/web/stock/aftertrading/
daily_trading_info/st43_print.php?l=zh-tw&d=105/12&stkno="
+ str(idnum) + "&s=0,asc,0")
df1=pd.read_html("http://www.tpex.org.tw/web/stock/aftertrading/
daily_trading_info/st43_print.php?l=zh-tw&d=106/01&stkno="
+ str(idnum) + "&s=0,asc,0")
detail=df[0]
detail1=df1[0]
detail_1=detail.drop(detail.tail(1).index)
detail1_1=detail1.drop(detail1.tail(1).index)
frames=[detail_1, detail1_1]
detail_c=pd.concat(frames)
# 檢查最新成交量/價是否符合條件
detail_c.columns=['date','volumn','quantity','open','high','low','close','change','number']
anys=pd.DataFrame([detail_c.tail(1)["volumn"] > detail_c["volumn"].mean()*3,
detail_c.tail(1)["close"] >
detail_c["close"].mean(),detail_c.tail(1)["number"] >
detail_c["number"].mean()*3])
anys.columns=[idnum]
return anys
#將不同股票的分析結果合併為一DF
dftotal=pd.concat([get_id(idnum) for idnum in (3646, 3213)], axis=1)
以上是新手純分享,傷眼勿怪
下面是問題,想請教各位大大
上櫃股票取得資訊很簡單,可以直接看到網址 (如
http://www.tpex.org.tw/web/stock/aftertrading/daily_trading_info/st43_print.php?l=zh-tw&d=106/01&stkno=3213&s=0,asc,0)
可是上市股票我就無法直接取得網址了(http://www.tse.com.tw/ch/trading/exchange/STOCK_DAY/STOCK_DAYMAIN.php)
因為我對html不熟,是否有前輩可以指導我該如何找到某上市股票的日成交明細的網址呢?
感謝指點
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 203.67.75.74
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1483607435.A.1CD.html
→
01/05 18:05, , 1F
01/05 18:05, 1F
→
01/05 20:44, , 2F
01/05 20:44, 2F
推
01/05 22:11, , 3F
01/05 22:11, 3F
推
01/06 03:54, , 4F
01/06 03:54, 4F
→
01/06 03:54, , 5F
01/06 03:54, 5F
→
01/06 08:30, , 6F
01/06 08:30, 6F
→
01/06 08:30, , 7F
01/06 08:30, 7F
→
01/06 10:18, , 8F
01/06 10:18, 8F
→
01/06 10:18, , 9F
01/06 10:18, 9F
→
01/06 10:19, , 10F
01/06 10:19, 10F
→
01/06 10:20, , 11F
01/06 10:20, 11F
→
01/06 10:20, , 12F
01/06 10:20, 12F
→
01/06 10:20, , 13F
01/06 10:20, 13F
→
01/06 10:21, , 14F
01/06 10:21, 14F
→
01/06 10:24, , 15F
01/06 10:24, 15F
→
01/06 10:24, , 16F
01/06 10:24, 16F
→
01/06 10:25, , 17F
01/06 10:25, 17F
→
01/06 10:25, , 18F
01/06 10:25, 18F
→
01/06 10:25, , 19F
01/06 10:25, 19F
→
01/06 10:26, , 20F
01/06 10:26, 20F
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):
2
20
Python 近期熱門文章
PTT數位生活區 即時熱門文章