开发者

html nested tables agility pack valid xpath

Assuming nested tables don't have unique attributes ( id , class or anything else ) to get the required one via 开发者_C百科

doc.DocumentNode.SelectSingleNode("//table[@width='500']")

Does XPath prohibit using table several times in its path ?

foreach (HtmlNode table in doc.DocumentNode.SelectNodes("//table/tr/center/table"))

throws exception as SelectNodes returns null.

If so how to tackle parsing of html with nested tables without specific attributes with Agility Pack ?


I just missed "td" tag in my path. So

foreach (HtmlNode table in doc.DocumentNode.SelectNodes("//table/tr/td/center/table/tr/td/center/table"))

does work. That actually answers my question. Other workaround to get the same table assuming there are unique attribute values in parent elements could be

HtmlNode tbl = doc.DocumentNode.SelectSingleNode("//td[@height='643']/center/table");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜