我对HTMLAgilityPack还是陌生的,不知道从何处开始或如何开始,有没有办法获取特定零件的价值。
<tr>
<td style="background-color: #584c4c;">
<img src="https://bnltradingcorp.com/assets/member/image/bitactive.gif" style="height: 15%;width: 40px;">
</td>
<td><span class="small1">44915d6e6f<span class="elipsis" style="display:none;">2b620c533c3909c355b009_REPURCHASED</span><a class="elipsis" href="#"> ...</a></span></td>
<td><i class="fa fa-euro"></i> 1327</td>
<td><i class="fa fa-euro"></i> 9.29</td>
<td>Nov 8, 2018 02:32:45 PM</td>
我只想获得“ 1327 ”和“ 9.29 ”部分,对不起,我提出了太多要求,但确实停留在这一部分。通过不使用HTMLAgillityPack即可获取内部文本的常规方法,它将显示所有这部分`` 44915d6e6f2b620c533c3909c355b009_REPURCHASED ... 1327 9.29 Nov 8,2018 02:32:45 PM '',而不是我想要的特定部分提取。
答案 0 :(得分:0)
Imports HtmlAgilityPack
Sub Grab()
Dim WebDoc As New HtmlDocument
WebDoc.LoadHtml(Webbrowser1.DocumentText)
Dim Table As HtmlNode = WebDoc.DocumentNode.SelectSingleNode("//form[@id='trading']/table/tbody") '// to search unlimited depth, @id to search for id element with name trading. /table/tbody to get inside completly
Dim TableRows As HtmlNodeCollection = Table.SelectNodes("./tr") '. is to "Start from here" compared to begging of html. Grab only td elements, as there is #text junk that we dont need
Dim LastRow As HtmlNodeCollection = TableRows.Last.SelectNodes("./td") 'one way of selcting it, from many. Also exclude just #text with additional td selector
For x = 2 To 3 'cells with index 2 and 3 are the ones we need
Debug.Print(LastRow(x).InnerText.Trim) 'do something here
Next
End Sub