抓取上櫃交易明細需要使用POST來傳遞參數,在VBA中能使用的方法就是使用XmlHttp。
不過我們想嘗試使用其他Excel VBA抓取網頁數據的方法來抓取,於是選用了Internet Explorer物件來試著抓取上櫃交易明細。
如下使用Internet Explorer物件抓取上櫃交易明細
Option Explicit
Sub ie_test_Navigate_PostData()
Dim objIE As Object
Dim bPostData() As Byte
Dim xlURL As String
Dim UrlHeaders As String
xlURL = "http://www.gretai.org.tw/ch/stock/aftertrading/broker_trading/download_ALLCSV.php"
UrlHeaders = "Content-Type: application/x-www-form-urlencoded" & vbCrLf
bPostData = StrConv("stk_date=1010914&curstk=5349", vbFromUnicode)
Set objIE = CreateObject("InternetExplorer.Application")
With objIE
.Visible = True
.Navigate xlURL, , , bPostData, UrlHeaders
While .ReadyState <> 4 Or .Busy = True
DoEvents
Wend
End With
End Sub
雖然可以透過InternetExplorer物件來抓取上櫃交易明細,但當順利取得檔案時卻因需要點選下載檔案對話框,因此這裡可能就無法使用InternetExplorer物件抓取。對於Navigate進階的使用可參考這裡。
沒有留言:
張貼留言