Sub XMLHTTP()
Dim t: t = Timer
Dim myXML As Object
Set myXML = CreateObject("Microsoft.XMLHTTP")
Dim myHTML As Object
Set myHTML = CreateObject("HTMLFile")
With myXML
.Open "GET", "https://jdata.yuanta.com.tw/z/zg/zgb/zgb0.djhtm?a=9800&b=9800&c=E&d=1", False
.send
myHTML.body.innerHTML = .responseText
Dim myTable As Object
Set myTable = myHTML.getElementsByTagName("Table")(3)
Dim oRow, oCell
Dim i As Integer, j As Integer
Dim oCellText As String
i = 1
For Each oRow In myTable.Rows
j = 1
For Each oCell In oRow.Cells
oCellText = oCell.innerText
Cells(i, j).Value = oCellText
j = j + 1
Next oCell
i = i + 1
Next oRow
End With
Set myXML = Nothing
Debug.Print Format(Timer - t, "0.00秒")
End Sub
成果圖
網頁部分原始碼:
Sub XMLHTTP()
Dim t: t = Timer
Dim myXML As Object
Set myXML = CreateObject("Microsoft.XMLHTTP")
Dim myHTML As Object
Set myHTML = CreateObject("HTMLFile")
With myXML
.Open "GET", "https://jdata.yuanta.com.tw/z/zg/zgb/zgb0.djhtm?a=9800&b=9800&c=E&d=1", False
.send
myHTML.body.innerHTML = .responseText
Dim myTable As Object
Set myTable = myHTML.getElementsByTagName("Table")(3)
Dim oRow, oCell
Dim i As Integer, j As Integer
Dim oCellText As String
i = 1
For Each oRow In myTable.Rows
j = 1
For Each oCell In oRow.Cells
oCellText = oCell.innerText
If oCellText = "" Then
Cells(i, j).Value = Split(Split(oRow.getElementsByTagName("script")(0).innerHTML, ",'")(1), "')")(0)
Else
Cells(i, j).Value = oCellText
End If
j = j + 1
Next oCell
i = i + 1
Next oRow
End With
Set myXML = Nothing
Debug.Print Format(Timer - t, "0.00秒")
End Sub
感謝老師的回覆
回覆刪除想了很久,找了資料都沒找到如何編寫,經老師提點,終於可以完成了
再次感謝老師