I want run a foreach
loop in a HtmlNode
which has been parsed from internet via HtmlWeb
class and loadFromWebAsync
method. Before running the loop I want to make sure the that the node exists in the HtmlDocument
. How do I check that without the help Xpath
query because many of the Windows RT
and Windows 8.1
version doesn't work with this.
You can use LINQ .Any()
method to check if sequence contains any element, for example :
var doc = new HtmlDocument();
.....
var isDivExist = doc.DocumentNode
.Descendants("div")
.Any();
Or to check if any node in the sequence satisfies specific condition :
var isDivWithSpecificClassExist = doc.DocumentNode
.Descendants("div")
.Any(d => .GetAttributeValue("class", "") == "foo");