標題:
用post方法抓上櫃個股,卻只能抓到框架的資料
[打印本頁]
作者:
tsunamix03
時間:
2016-12-11 09:55
標題:
用post方法抓上櫃個股,卻只能抓到框架的資料
請教各位先進
不知為什麼使用post方法抓上櫃資料,卻只能抓到一些表格標頭的資料
表格內的資料抓不到
感謝各位先進
Dim starttime As Variant
Dim fountrow As Integer, col As Integer, row As Integer
starttime = Now()
Dim path As String, thePOSTdata, URL
Dim stockID As Integer
col = 0
row = 1
stockID = 1258
y = 105
Z = 12
URL = "http://www.tpex.org.tw/web/stock/aftertrading/daily_trading_info/st43.php" '?l=zh-tw"
Set XML = CreateObject("Microsoft.XMLHTTP")
Set Stream = CreateObject("ADODB.stream")
'l: zh -tw
'd:105/01
'stkno:2235
'_:1480605726849
'http://www.tpex.org.tw/web/stock/aftertrading/daily_trading_info/st43_result.php?l=zh-tw&d=105/09/01&stkno=2732&_=1480599462728
thePOSTdata = "l=zh-tw&d=" & y & "/" & Z & "&stkno=" & stockID & "&_=1480599462728"
XML.Open "POST", URL, 0
XML.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
XML.send thePOSTdata
With Stream
.Type = 1
.Mode = 3
.Open
.Write XML.ResponseBody
.Position = 0
.Type = 2
.Charset = "Big5"
ByteToText = .ReadText
'strText = XML.responseText
'MsgBox strText
MsgBox ByteToText
Dim arr() As String
arr = Split(ByteToText, Chr(10)) 'Chr(10)代表Enter鍵嗎???
Dim processstring As String
For i = 0 To UBound(arr)
MsgBox arr(i)
processstring = Replace(arr(i), """,""", "^^")
'putdata = Split(arr(i), "^^")
putdata = Split(processstring, "^^")
For j = 0 To UBound(putdata)
Sheets(2).Cells(row, j + 1 + col).Select
Sheets(2).Cells(row, j + 1 + col).NumberFormatLocal = "@"
'工作表1.Cells(i + 1, j + 1).Value = CStr(Replace(Replace(putdata(j), """", ""), "=", ""))
'MsgBox putdata(j)
ShowString = Replace(Trim(putdata(j)), ",", "")
ShowString = Replace(ShowString, """", "")
ShowString = Replace(ShowString, "=", "")
Sheets(2).Cells(row, j + 1 + col).Value = ShowString
Next j
row = row + 1
Next i
End With
附件為excel檔案
[attach]26068[/attach]
作者:
joey0415
時間:
2016-12-11 18:31
本帖最後由 joey0415 於 2016-12-11 18:33 編輯
回復
1#
tsunamix03
http://www.tpex.org.tw/web/stock/aftertrading/daily_trading_info/st43_result.php?l=zh-tw&d=
105/12
&stkno=
3122
紅字的地方自己改改,剩下的你的程式碼都能辦到才是
用 get 不是 post
[attach]26071[/attach]
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)