htmlagilitypack:在div中查找第二个表 [英] htmlagilitypack: Find second table within a div
本文介绍了htmlagilitypack:在div中查找第二个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从其中具有3个表的div
解析信息.我可以从第一个那里毫无问题地获取信息.
I'm trying to parse information from a div
that has 3 tables within it. I can get information from the first one without problem.
代码如下:
HtmlAgilityPack.HtmlWeb doc = new HtmlAgilityPack.HtmlWeb();
HtmlAgilityPack.HtmlDocument htmldocObject = doc.Load(URL);
var res = htmldocObject.DocumentNode.SelectSingleNode("//div[@class='BoxContent']");
var firstTable = res.SelectSingleNode("//table");
var charName = firstTable.ChildNodes[i++].InnerText.Substring(5).Trim();
<div class="BoxContent">
<table>
<tr bgcolor=#505050>
<td colspan=2 class=white>
<b>I'm getting this text</b>
</td>
</tr>
<tr bgcolor=#F1E0C6>
<td>I get this too</td>
<td>I'm getting this as well</td>
</tr>
</table>
<table>
<tr>
<td>Trying to retrieve this</td>
</tr>
</table>
</div>
如何使用HAP查找第二张表信息?
How can I find the second table information with HAP?
我已经阅读了一些有关nextsibling函数的信息,但是我无法使其正常工作.
I've read some about nextsibling function but I can't get it to work.
推荐答案
var secondTable = res.SelectSingleNode("//table[2]");
这篇关于htmlagilitypack:在div中查找第二个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文