I have the following HTML
(..)
Test1
Data
-
As for your attempt, you have two issues with your code:
ChildNodes
is weird - it also returns whitespace text nodes, which don't have a class
attributes (can't have attributes, of course).
- As James Walford commented, the spaces around the text are significant, you probably want to trim them.
With these two corrections, the following works:
var data =
from tr in doc.DocumentNode.Descendants("tr")
from td in tr.Descendants("td").Where(x => x.Attributes["class"].Value == "name")
where td.InnerText.Trim() == "Test1"
select tr;
- 热议问题