請高手大師相助
要取得網頁中的資料須先選擇項目,但就不知如何做
例如這個網頁,選擇其中一個選項頁面的內容就更新了- Sub EX()
- Dim URL As String, A As Object, i As Integer, j%
- Dim AA, BB, AB$, stationName$
- URL = "http://e-service.cwb.gov.tw/HistoryDataQuery/index.jsp"
- Application.StatusBar = "查詢網頁 ..."
- With CreateObject("InternetExplorer.Application")
- .Visible = True ' 是否顯示 IE
- .Navigate URL
- Do While .ReadyState <> 4
- DoEvents
- Loop
- Application.Wait Time + #12:00:05 AM# '等候網頁
- Set A = .document.All
- On Error Resume Next
- For i = 0 To A.Length - 1
- If A(i).tagname = "OPTION" Then
- If A.Item(i).Value <> "" Then
- AA = AA & "," & A(i).Value '取得測站編碼
- BB = BB & "," & A(i).innertext '取得選擇項
- End If
- End If
- Next
- AA = Split(AA, ",") 'String to Array
- BB = Split(BB, ",")
-
- ' 底下是問題點,如何變換網頁中之 "測站" 選項 使頁面更新===============
- '======== 及 "資料格式" 選項 來更新網頁資料 ========================
- ' For i = 0 To UBound(BB)
- ' .document.getElementsBytagname("SELECT").Value = BB(i)
- ' .submit
- ' Next
- ' 以上是問題 =========================
- .ExecWB 17, 2 'Select All
- .ExecWB 12, 2 'Copy selection
-
- With ActiveSheet
- .Cells.Clear
- .Range("A1").Activate
- .PasteSpecial Format:="HTML", Link:=False, DisplayAsIcon:= _
- False, NoHTMLFormatting:=True
- End With
-
- .Quit
- End With
- Application.StatusBar = False
- End Sub
複製代碼 |