how can htmlagilitypack check if nodes exist on webpage?

html-agility-pack

Question

Using Vb.net and HtmlAgilityPack is there a way to check if the node exists on the webpage before selecting the node ?

While running my program, if the node doesn't exist at all on the page, I am getting a null exception error message.

I don't want to use

If firsttag(0).InnerText IsNot Nothing Then 

as by using this, the program is already trying to get the value of the node.

I would like to scan the webpage first to see if the node exists

Dim firsttag As HtmlAgilityPack.HtmlNodeCollection = docnews.DocumentNode.SelectNodes("//div[(@class='byline')]") 

Is there anything like

if firsttage(0) search does not exist then Continue For Else 

Popular Answer

Check whether firstTag returns Nothing or if it returns an empty list:

 If (firstTag IsNot Nothing and firstTag.Any() and firstTag.First().InnerText IsNot Nothing Then


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why