'重大訊息公佈網頁
IE.Navigate "http://mops.twse.com.tw/mops/web/t05sr01_1"
Do: DoEvents: Loop Until IE.readyState = READYSTATE_COMPLETE
Dim doc As HTMLDocument
Set doc = IE.document
'按下"詳細資料" button
Set docinput = doc.getElementsByTagName("input")
r = 1
For i = 0 To docinput.Length - 1
If docinput(i).Value = "詳細資料" And docinput(i).Type = "button" Then
'???按下"詳細資料"button, 有時有問題???
docinput(i).Click
Do: DoEvents: Loop Until IE.readyState = READYSTATE_COMPLETE
'進入"詳細資料"頁面後,開始抓取主要內容。主要訊息內容為 table(9)
Set A = doc.getElementsByTagName("table")(9)
Do: DoEvents: Loop Until IE.readyState = READYSTATE_COMPLETE
'將主要訊息內容放入 sheet
For j = 1 To A.Rows(4).Cells.Length - 1
Sheets(1).Cells(r, j + 1).Select
Sheets(1).Cells(r, j + 1).Value = A.Rows(4).Cells(j).innerText
Next j
r = r + 1
'抓完訊息內容後,返回上一頁
For Each img In doc.getElementsByTagName("img")
If img.href = "http://mops.twse.com.tw/mops/web/images/bu_05.gif" Then
'???img.click 有時無動作???
img.Click
Do: DoEvents: Loop Until IE.Busy = False And IE.readyState = READYSTATE_COMPLETE
Exit For
End If
Next
End If
Next i
IE.Quit作者: stillfish00 時間: 2016-1-12 15:53