<div id="Fruits" class="item">
<table>
<tbody><tr>
<td class="header">Category</td>
<td class="text">
<span id="aaaaa" class="Name"><a href="" rel="category tag">Apple</a></span>
<span id="bbbbb" class="Name"><a href="" rel="category tag">Orange</a></span>
<span id="ccccc" class="Name"><a href="" rel="category tag">Melon</a></span>
<span id="ddddd" class="Name"><a href="" rel="category tag">Banana</a></span>
<span id="ddddd" class="Name"><a href="" rel="category tag">Watermelon</a></span>
<td class="icon"></td>
</tr>
</tbody></table>
</div>
我想通过VB WebBrowser获取“Apple”,“Orange”,“Melon”,“Banana”,“Watermelon”,但是当我使用代码时
WebBrowser2.Document.GetElementById("Fruits").GetAttribute("innerText")
我得到了AppleOrangeMelonBananaWatermelon
是否可以单独获取或者在
之间使用逗号苹果,桔子,甜瓜,香蕉,西瓜
提前致谢
答案 0 :(得分:0)
我可以使用xPath语法为您提供替代方案。我不知道你是否可以将xPath与对象“webBrowser”一起使用,但这是一个完整的替代方案。我希望这可以帮助你。
Private Sub stackOverflowExample()
Dim client As WebClient = New WebClient()
Dim lnk As String = "http://www.example.com"
Try
Dim html = client.DownloadString(lnk)
Dim htmlDoc As New HtmlAgilityPack.HtmlDocument()
htmlDoc.LoadHtml(html)
For Each node As HtmlNode In htmlDoc.DocumentNode.SelectNodes("//span[@id='fruits']")
' get inner html ---> node.InnerHtml
Next
Catch ex As Exception
End Try
End Sub