返回列表 上一主題 發帖

[發問] 有大大能找到鉅亨網的隱藏網址嗎?以及網頁元素問題

回復 1# PKKO

試試看
  1. Option Explicit
  2. Sub testDL()   '下載股票資訊
  3.     Dim IE As Object, st_date As String, xTable As Object, R As Integer, C As Integer
  4.     st_date = "2016/02/01"
  5.     Set IE = CreateObject("InternetExplorer.Application")
  6.     IE.Visible = True
  7.     IE.Navigate "http://www.cnyes.com/twstock/ps_historyprice/" & "3514" & ".htm"
  8.     Do While IE.readyState <> 4: DoEvents: Loop
  9.     With IE.Document
  10.         R = .ALL.tags("table")(1).Rows.Length ' '**資料數(含表頭): 網頁預設顯示為一個月的資料
  11.         '開始日期
  12.         ' ************* 有ID 可直接用ID的名稱********
  13.         .GetElementByid("ctl00_ContentPlaceHolder1_startText").Value = st_date
  14.         Do While IE.readyState <> 4 Or IE.Busy: DoEvents: Loop
  15.         'For Each E In .GetElementsByTagName("INPUT")
  16.         '    If E.ID = "ctl00_ContentPlaceHolder1_startText" Then
  17.         '        E.Value = st_date: Exit For
  18.         '    End If
  19.         'Next
  20.         '查詢按鈕
  21.         .GetElementByid("ctl00_ContentPlaceHolder1_submitBut").Click
  22.         'For Each E In .GetElementsByTagName("INPUT")
  23.         '    If E.ID = "ctl00_ContentPlaceHolder1_submitBut" Then
  24.         '        E.Click: Exit For
  25.         '    End If
  26.         'Next
  27.         '=================================下載資料=================================
  28.         Do While IE.readyState <> 4 Or IE.Busy: DoEvents: Loop    '這行程式碼無效,無法真的等待網頁執行時間

  29.         Do
  30.             DoEvents
  31.             Set xTable = .ALL.tags("table")(1)
  32.             If xTable.Rows.Length <> R And xTable.Rows.Length > 1 Then Exit Do ''** 等候資料日數等於指定的日數
  33.             ' 等後資料下載時: xTable.Rows.Length=1
  34.         Loop
  35.         '=================================下載資料=================================
  36.         With ActiveSheet
  37.             .UsedRange = ""
  38.             For R = 0 To xTable.Rows.Length - 1
  39.                 For C = 0 To xTable.Rows(R).Cells.Length - 1
  40.                     .Cells(R + 1, C + 1) = xTable.Rows(R).Cells(C).innertext
  41.                 Next
  42.             Next
  43.         End With
  44.         MsgBox "資料下載完成!"
  45.     End With
  46.     IE.Quit
  47. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 10# PKKO


   



感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 自己害自己,莫過於亂發脾氣。
返回列表 上一主題