返回列表 上一主題 發帖

[發問] 上市股票融資融券餘額CSV下載問題

回復 12# hipper68

你試試看,應該可行!
  1. Sub ex()

  2.     With CreateObject("internetexplorer.application")
  3.         .Visible = True
  4.         .Navigate "http://www.twse.com.tw/ch/trading/exchange/MI_MARGN/MI_MARGN.php"
  5.         Do Until .ReadyState = 4
  6.             DoEvents
  7.         Loop
  8.         
  9.         .Document.getElementById("date-field").Value = "104/08/12" '填入
  10.          
  11.         '---------,內建的fireevent 的onchange失效,改用調用js的方法--------
  12.         Set evt = .Document.createEvent("HTMLEvents")
  13.         evt.initEvent "change", True, False
  14.         Set lst = .Document.all("selectType") 'option的name是selectType,但getElementsByName無法處理,要all才行
  15.         lst.selectedIndex = 0
  16.         lst.dispatchEvent evt
  17.    
  18.         .Document.all("query-button").Click


  19.          Do While .ReadyState <> 4 Or .Busy: DoEvents: Loop

  20.         Application.Wait Now + TimeValue("00:00:5")
  21. '        Stop
  22.         
  23. '        For Z = 0 To 10
  24. '        MsgBox .Document.getElementsByTagName("table")(Z).innerText
  25. '        Next
  26.             Stop
  27.         Set hTable = .Document.getElementsByTagName("table")(3) '第4個table
  28. '        tt = hTable.Rows.Length
  29. '        qq = hTable.Rows(2).Cells.Length

  30.             With ActiveSheet
  31.                 For i = 1 To hTable.Rows.Length - 1 '前3個是標題與空白跳過
  32.                     For j = 0 To hTable.Rows(i).Cells.Length - 1
  33.                         .Cells(i, j + 1) = hTable.Rows(i).Cells(j).innerText
  34.                     Next
  35.                 Next
  36.             End With

  37.         .Quit
  38. '        MsgBox "OK"
  39.     End With
  40.    
  41. End Sub
複製代碼

TOP

        靜思自在 : 為自己找藉口的人永遠不會進步。
返回列表 上一主題