How would I use HTMLAgilityPack to extract the value I want

Posted by Nai on Stack Overflow See other posts from Stack Overflow or by Nai
Published on 2010-12-30T17:12:11Z Indexed on 2010/12/30 17:54 UTC
Read the original article Hit count: 337

Filed under:
|
|

For the given HTML I want the value of id

 <div class="name" id="john-5745844">
 <div class="name" id="james-6940673">

UPDATE This is what I have at the moment

    HtmlDocument htmlDoc = new HtmlDocument();
    htmlDoc.Load(new StringReader(pageResponse));
    HtmlNode root = htmlDoc.DocumentNode;

    List<string> anchorTags = new List<string>();
    foreach (HtmlNode div in root.SelectNodes("//div[@class='name' and @id]"))
    {
        HtmlAttribute att = div.Attributes["id"];
        Console.WriteLine(att.Value);
    }

The error I am getting is at the foreach line stating: Object reference not set to an instance of an object.

© Stack Overflow or respective owner

Related posts about c#

Related posts about html-parsing