"Object reference not set to an instance of an object."
using System.Text; using HtmlAgilityPack; namespace HtmlParser { class Program { static void Main(string[] args) { // The HtmlWeb class is a utility class to get the HTML over HTTP HtmlWeb htmlWeb = new HtmlWeb(); // Creates an HtmlDocument object from an URL HtmlAgilityPack.HtmlDocument document = htmlWeb.Load("http://allrecipes.com/search/default.aspx?w0=chicken&w1=beef"); // Targets a specific node HtmlNode content_wrapper = document.GetElementbyId("content-wrapper"); System.Console.WriteLine(content_wrapper.ToString()); HtmlNodeCollection search_results = content_wrapper.SelectNodes("//div[@class='searchResult']"); foreach (HtmlNode result in search_results) { string recipe_name = result.SelectSingleNode("*[@class='resultTitle']").InnerText;// error appears here System.Console.WriteLine(recipe_name); } System.Console.ReadKey(); } } }
class
content_wrapper
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)