Click here to Skip to main content
12,301,394 members (59,811 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# HTML HTTP Parsing
I have the following code in C# but it is not working. I am new to the whole C# and parsing thing but I need to get this working. Anyone knows why i am getting:"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("");
            // Targets a specific node
            HtmlNode content_wrapper = document.GetElementbyId("content-wrapper");
            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
[Edit]Code block added[/Edit]
Posted 5-Dec-12 7:38am
Edited 5-Dec-12 7:41am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I think there's no HTML-element with your search result as class in your content_wrapper element.
Anselmo santos 6-Dec-12 10:47am
How do I solve that issue people?
ProgramFOX 6-Dec-12 11:12am
Try another search than the search you tried.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.160525.2 | Last Updated 5 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100