Click here to Skip to main content
Rate this: bad
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 8:38am
Edited 5-Dec-12 8: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 at 6-Dec-12 10:47am
How do I solve that issue people?
ProgramFOX at 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
0 OriginalGriff 545
1 Maciej Los 475
2 Sascha Lefévre 289
3 CPallini 285
4 Sergey Alexandrovich Kryukov 274
0 Sergey Alexandrovich Kryukov 9,897
1 OriginalGriff 9,395
2 Peter Leow 5,162
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 3,036

Advertise | Privacy | Mobile
Web03 | 2.8.150327.1 | Last Updated 5 Dec 2012
Copyright © CodeProject, 1999-2015
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