Option Explicit
Sub Sample()
Dim objIe As InternetExplorerMedium
Dim xobj As Variant
Dim links As Variant
Dim link As String
Dim lnk As Variant
Dim rc As Integer
Set objIe = New InternetExplorerMedium
objIe.Visible = True
objIe.navigate "C:\Users\SOURABH\Desktop\test.html"
Do While objIe.Busy And Not objIe.readyState = 4
Application.StatusBar = "Loading.."
DoEvents
Loop
MsgBox objIe.document.body.innerHTML
Set xobj = objIe.document.getElementByTagName("myDiv")
Set xobj = xobj.getElementsByClassName("myTable").Item(0)
Set xobj = xobj.getElementsByClassName("data")(0)
For Each lnk In links
MsgBox "lnk got accessed"
If lnk.className = "myTable" Then
Sheets("Sheet1").Cells(3, 1).Value = lnk(0).innerText
Exit For
End If
Next
MsgBox xobj.innerText
Set xobj = Nothing
objIe.Quit
Set objIe = Nothing
End Sub
还有我的 HTML:
<div id="myDiv">
<table class="myTable">
<tbody>
<tr>
<td>Text1:</td>
<td class="data"><strong>0.51</strong></td>
</tr>
<tr>
<td>Text2:</td>
<td class="data"><strong>2199</strong></td>
</tr>
</tbody>
</table>
</div>
我可以使用 MsgBox 命令查看内部文本,但是在获取内部文本中的类名时出现错误:
对象在 set xobj = objIe.document.getElementByTagName("myDiv") 行中不支持此属性
请帮我找到一种方法来获取类“数据”的内部文本