- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
回復 1# GaryC - With .Document
- .all("myear").Value = Year(xDate) - 1913 '日期可修改
- MsgBox .getElementsByName("myear")(0).Value
- .all("mmon").Value = Format(Month(xDate) - 1, "0#")
- For Each E In .GetElementsByTagName("INPUT")
- If E.Value = "查詢" Then E.Click
- Next
- End With
複製代碼 每一個網頁(HTM )的建置都不一樣.- Option Explicit
- Sub Ex_網頁元素()
- Dim i As Integer, E As Object
- With CreateObject("InternetExplorer.Application")
- .Visible = True
- .Navigate "http://www.twse.com.tw/ch/trading/indices/MI_5MINS_HIST/MI_5MINS_HIST.php"
- Do While .Busy Or .readyState <> 4: DoEvents: Loop
- With .Document
- '*** 這段程式碼可查看這網頁的元素內容
- On Error Resume Next
- For Each E In .all
- i = i + 1
- Cells(i, "a") = E.tagname '使用 .GetElementsByTagName("INPUT")
- Cells(i, "b") = E.ID '使用 .GetElementByID("menu")
- Cells(i, "c") = E.Name '使用 .all("myear")
- '.getElementsByName("myear")(0).Value ' = Year(xDate) - 1911
- ' HTML 中通常具有相同的 name 屬性),所有 getElementsByName() 方法返回的是元素的集合,而不是單一個元素。
- Cells(i, "d") = E.Value
- Cells(i, "e") = E.innertext
- Cells(i, "f") = E.Type
- Cells(i, "g") = E.href
- Next
- End With
- ' .Quit '關閉網頁
- End With
- End Sub
複製代碼 |
|