返回列表 上一主題 發帖

[發問] 鉅亨網 技術指標 VBA抓取問題

回復 1# espionage
Application.Wait Now + #12:00:10 AM#   '在程式中'等候10秒
等候10秒 不一定等的到
  1. Option Explicit
  2. Sub Ex()
  3.     Dim mysearchrange As Integer, mysearchdate As String, xR As Integer, xC As Integer
  4.     Dim xTable As Object, A As Object, C As Object, myopt As Object
  5.     For mysearchrange = 2 To 3  '設定要尋找的日期
  6.         mysearchdate = Sheets("總表").Cells(mysearchrange, 5)  '日期格式 yyyy-mm-dd
  7.         With CreateObject("InternetExplorer.Application")
  8.             .Visible = True
  9.             .Navigate "http://www.cnyes.com/twstock/a_technical2.aspx"
  10.             Do While .Busy Or .readyState <> 4: DoEvents: Loop
  11.             With .Document
  12.                 '--------------------輸入要查詢的股票市場
  13.                 For Each A In .getElementsByTagName("SELECT")
  14.                     If A.Name = "ctl00$ContentPlaceHolder1$D1" Then
  15.                         For Each myopt In A.Options
  16.                             If myopt.innertext = "集中市場" Then
  17.                                 myopt.Selected = True
  18.                                 GoTo SeLe1
  19.                             End If
  20.                         Next
  21.                     End If
  22.                 Next
  23. SeLe1:         '-------------------輸入要查詢的日期範圍
  24.                 For Each A In .getElementsByTagName("SELECT")
  25.                     If A.Name = "ctl00$ContentPlaceHolder1$D3" Then
  26.                         For Each myopt In A.Options
  27.                             If myopt.innertext = mysearchdate Then
  28.                                 myopt.Selected = True
  29.                                 A.fireEvent ("onchange")
  30.                                 GoTo SeLe2
  31.                             End If
  32.                         Next
  33.                     End If
  34.                 Next
  35. SeLe2:
  36.             End With
  37.             Do While .Busy Or .readyState <> 4: DoEvents: Loop
  38.             Do Until InStr(.Document.getElementByid("ctl00_ContentPlaceHolder1_UpdatePanel1").innertext, mysearchdate)
  39.                 '等候下載:指訂日期資料
  40.                 DoEvents
  41.             Loop
  42.             Set xTable = .Document.getElementsByTagName("TABLE")(1)
  43.             ActiveSheet.UsedRange.Clear
  44.             For Each A In xTable.Rows   'Table的Rows物件集合
  45.                 xR = xR + 1                 '下一列號
  46.                 xC = 1
  47.                 For Each C In A.Cells       'Table的Row物件的Cells物件集合
  48.                     Cells(xR, xC) = C.innertext
  49.                     xC = xC + 1
  50.                 Next
  51.             Next
  52.         End With
  53.     Next
  54. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 閒人無樂趣,忙人無是非。
返回列表 上一主題