对某人来说这可能很简单,所以如果您是那个人,请看一下:
我的表中有更多行,但是我想根据给定的文本提取一行,这是表摘录:
... <tr>
<td class="border-1px-solid-black" colspan="1">
<img onclick="PopupCenter('{{InvoiceDetails.0.Link}}')" style="max-height: 35px; max-width: 35px; cursor: pointer;" src="/images/report.png" /></td>
<td class="border-1px-solid-black" colspan="11">
<p>{{InvoiceDetails.0.Description}}</p>
</td>
<td class="border-1px-solid-black" colspan="2" style="text-align: right;">
<p>{{InvoiceDetails.0.Quantity}}</p>
</td>
<td class="border-1px-solid-black" colspan="2" style="text-align: right;">
<p>{{InvoiceDetails.0.Amount}} </p>
</td>
</tr>...
我正在使用HtmlAgilityPack和VB.NET,并且我想获取在任何元素中都包含InvoiceDetails.0的TR。
如何做?
谢谢!
我将以完成此操作的方式发布,但这不是最短的方法:
nodes = doc.DocumentNode.SelectNodes("//*[text()[contains(., '" + find + "')]]")
If nodes IsNot Nothing Then
node = nodes(0)
While node.ParentNode.Name <> "tr"
node = node.ParentNode
End While
node = node.ParentNode
'and here I have reference to TR node
Next
End If
如果您的方法比较短,请在这里写。