I am tyring to use HtmlAgilityPack to scrape a web page for a certain nested div class that contains a span tag with the data I want to extract
The full XPath to the element's text I want:
/html/body/div[2]/div/div[1]/div/table/tbody/tr/td/span
My code:
static void Main(string[] args)
{
HtmlAgilityPack.HtmlWeb web = new HtmlAgilityPack.HtmlWeb();
HtmlAgilityPack.HtmlDocument doc = web.Load("http://watchout4snakes.com/wo4snakes/Random/RandomParagraph");
var paragraph = doc.DocumentNode.SelectNodes("//div[@class='mainBody']//div[@class='content']//div[@class='resultContainer']" +
"//div[@class='resultBox']//table[@class='paragraphResult']").ToList();
foreach (var item in paragraph)
{
Console.WriteLine(item.InnerText);
}
}
I've tried putting the full XPath into the doc.DocumentNode.SelectNodes() as well as just the Xpath which is //*[@id='result']
My issue is that it either returns nothing or I get an error saying Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'source') on the doc.DocumentNode.SelectNodes() line.