返回列表 上一主題 發帖

大盤歷史資料查詢

本帖最後由 GBKEE 於 2016-1-11 14:06 編輯

回復 2# kim223824
  1. Option Explicit
  2. Sub Ex_TABLE() '查看大盤歷史資料查詢,資料所在的TABLE
  3.     Dim i As Integer, E As Object, url, xTable, A
  4.     url = "http://www.twse.com.tw/ch/trading/indices/MI_5MINS_HIST/MI_5MINS_HIST.php"
  5.     With CreateObject("InternetExplorer.application")
  6.         .Visible = True
  7.         .Navigate url
  8.         Do While .Busy Or .readyState <> 4: DoEvents: Loop
  9.         With .Document
  10.             .ALL("myear").Value = "104"
  11.             .ALL("mmon").Value = "12"
  12.             For Each E In .ALL.tags("input")
  13.                 If E.Type = "button" And E.Value = "查詢" Then
  14.                     E.Click
  15.                     Exit For
  16.                 End If
  17.             Next
  18.         End With
  19.         Do While .Busy Or .readyState <> 4: DoEvents: Loop
  20.         Set xTable = .Document.getElementsByTagName("TABLE")
  21.         On Error Resume Next
  22.             For Each E In xTable
  23.                     i = i + 1
  24.                     Cells(i, 1) = A   '查看資料在那一個TABLE
  25.                     A = A + 1
  26.                     i = i + 1
  27.                    Cells(i, "A") = E.innertext
  28.             Next
  29.         .Quit        '關閉網頁
  30.     End With
  31. End Sub
複製代碼
  1. Option Explicit
  2. Sub 大盤指數20160110()
  3.     Dim xTable As Object, k As Integer, c As Integer, r As Integer
  4.     Dim url As String, i As Integer, E As Object
  5.     'Sheets("下載").Select
  6.     url = "http://www.twse.com.tw/ch/trading/indices/MI_5MINS_HIST/MI_5MINS_HIST.php"
  7.         With CreateObject("InternetExplorer.application")
  8.         .Visible = True
  9.         .Navigate url
  10.         Do While .Busy Or .readyState <> 4: DoEvents: Loop
  11.                  With .Document
  12.                     .ALL("myear").Value = "104"
  13.                     .ALL("mmon").Value = "12"
  14.                    ' .all("onclick").Click                    '按下按鍵的
  15.                     For Each E In .ALL.tags("input")
  16.                         If E.Type = "button" And E.Value = "查詢" Then
  17.                             E.Click        '按下查詢鍵
  18.                             Exit For
  19.                         End If
  20.                     Next
  21.                 End With
  22.         Do While .Busy Or .readyState <> 4: DoEvents: Loop
  23.         'Sub Ex_TABLE() 查看大盤歷史資料查詢,得知資料所在的TABLE
  24.         Set xTable = .Document.getElementsByTagName("TABLE")(10) '資料在這
  25.         With Sheets("下載")
  26.             .UsedRange.Clear
  27.             k = k + 1
  28.             For r = 0 To xTable.Rows.Length - 1
  29.                 For c = 0 To xTable.Rows(r).Cells.Length - 1
  30.                     .Cells(k, c + 1) = xTable.Rows(r).Cells(c).innertext
  31.                 Next
  32.                 k = k + 1
  33.             Next
  34.         End With
  35.         .Quit
  36.     End With
  37. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 4# kim223824
  1. Option Explicit
  2. Sub Ex_Table() '查看大盤歷史資料查詢,資料所在的TABLE
  3.     Dim i As Integer, E As Object, URL, xTable As Object
  4.     Dim xR As Integer, xT As Integer, R As Object, C As Object
  5.     URL = "http://www.twse.com.tw/ch/trading/indices/MI_5MINS_HIST/MI_5MINS_HIST.php"
  6.     With CreateObject("InternetExplorer.application")
  7.         .Visible = True
  8.         .Navigate URL
  9.         Do While .Busy Or .readyState <> 4: DoEvents: Loop
  10.         With .document
  11.             .ALL("myear").Value = "104"
  12.             .ALL("mmon").Value = "12"
  13.             For Each E In .ALL.tags("input")
  14.                 If E.Type = "button" And E.Value = "查詢" Then
  15.                     E.Click
  16.                     Exit For
  17.                 End If
  18.             Next
  19.         End With
  20.         Do While .Busy Or .readyState <> 4: DoEvents: Loop
  21.         Set xTable = .document.getElementsByTagName("TABLE")
  22.         ActiveSheet.UsedRange.Clear
  23.         xR = 1                              '工作表列號
  24.         For xT = 0 To xTable.Length - 1
  25.             Cells(xR, 1) = "第" & xT & "Table"
  26.             For Each R In xTable(xT).Rows   'Table的Rows物件集合
  27.                 xR = xR + 1                 '下一列號
  28.                 i = 1
  29.                 For Each C In R.Cells       'Table的Row物件的Cells物件集合
  30.                     Cells(xR, i) = C.innertext
  31.                     i = i + 1
  32.                 Next
  33.             Next
  34.             xR = xR + 1                      '下一列號
  35.         Next
  36.         .Quit        '關閉網頁
  37.     End With
  38. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 發脾氣是短暫的發瘋。
返回列表 上一主題