Click here to Skip to main content
11,709,033 members (61,848 online)
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 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 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 Sergey Alexandrovich Kryukov 580
1 Maciej Los 235
2 Peter Leow 219
3 OriginalGriff 214
4 Mika Wendelius 170
0 OriginalGriff 9,348
1 Sergey Alexandrovich Kryukov 8,727
2 CPallini 5,189
3 Maciej Los 4,991
4 Mika Wendelius 3,856

Advertise | Privacy | Mobile
Web03 | 2.8.150819.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