我想从td rowspan&获取数据td colspan都具有相同的类(ng-binding)。我需要来自td rowspan =“4”的输出100和来自td colspan =“6”的38.6%。 以下是我的HTML代码:
<td rowspan="4" class="ng-binding">Subscription used in terms of Duration:100</td>
<td colspan="6" class="ng-binding">38.6%</td>
以下是我尝试过的代码但收到错误消息运行时错误'438'对象不支持Set TDs = driver.findElementByClassName("ng-binding")
Sub edit()
Dim driver As New selenium.FirefoxDriver
driver.Get "url"
Dim TDs As IHTMLElementCollection
Dim td As IHTMLElement
Set TDs = driver.findElementByClass("ng-binding")
For Each td In TDs
If InStr(td.innerHTML, "rowspan=""4""") > 0 Then s = td.innerText
If InStr(td.innerHTML, "td colspan=""6""") > 0 Then
s = td.innerText
s = Right(s, Len(s) - InStr(s, ":"))
End If
Debug.Print s
Next td
End Sub
答案 0 :(得分:0)
假设html变量是宏下载的html代码。我会这样做:
Dim TDs As IHTMLElementCollection
Dim td As IHTMLElement
Set TDs = html.getElementsByClassName("ng-binding")
For Each td In TDs
If InStr(td.innerHTML, "rowspan=""4""") > 0 Then s = td.innerText
If InStr(td.innerHTML, "td colspan=""6""") > 0 Then
s = td.innerText
s = Right(s, Len(s) - InStr(s, ":"))
End If
Debug.Print s
Next td
如果&lt;中只有一个“:”它应该有效。 td rowspan =“4”class =“ng-binding”&gt;。