返回列表 上一主題 發帖

[發問] VBA 抓取網路表格

[發問] VBA 抓取網路表格

各位程式高手好,小弟想做程式抓取像鉅亨網這類的網站資料
http://www.cnyes.com/twstock/ps_historyprice/1101.htm

已能做到鍵入起始日期及查詢,但抓取資料的程式寫不出來。
爬過其他文,都是TABLE有id,但這種的不知從何下手,
請求協助。
  1. Sub Website()


  2.     Dim doc As Object
  3.     Set IE = CreateObject("internetexplorer.application")
  4.      With IE
  5.     IE.Visible = True

  6. navigate:
  7.     IE.navigate "http://www.cnyes.com/twstock/ps_historyprice/1101.htm"
  8.                 'http://www.cnyes.com/twstock/ps_historyprice/1101.htm'

  9.     Do While IE.ReadyState <> 4: DoEvents: Loop

  10.     Set doc = CreateObject("htmlfile")
  11.     Set doc = IE.document

  12.     If doc Is Nothing Then GoTo navigate

  13.     Set txtDtBegin = doc.getelementbyid("ctl00_ContentPlaceHolder1_startText")  '開始日期'
  14.         txtDtBegin.Value = "2015/11/23"
  15.     Set txtDtEnd = doc.getelementbyid("ctl00_ContentPlaceHolder1_endText")      '結束日期'
  16.         txtDtEnd.Value = "2015/11/25"
  17.    
  18.     Set element = doc.getelementbyid("ctl00_ContentPlaceHolder1_submitBut")     '點擊按鈕'
  19.         element.Click
  20.          
  21.          
  22.     Do While .Busy Or .ReadyState <> 4: DoEvents: Loop
  23.     End With
  24.   
  25. End Sub
複製代碼

回復 1# 52028

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

TOP

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