locked
HTML Agility - Only one record is being found in the code below RRS feed

  • Question

  • User-1188570427 posted
    I am trying to obtain ALL of the div tags with a certain class.

    The code below runs fine, but only one record comes back.

    What am I doing wrong?

                using (WebClient client = new WebClient())
                {
                    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                    string html = client.DownloadString("https://myurl.com");
    
                    doc.LoadHtml(html);
    
                    var findDivs = doc.DocumentNode.Descendants().Where(d =>
                                d.Attributes.Contains("class") && d.Attributes["class"].Value.Contains("list-mode-table-wrapper")
                            ).Select(x => x).ToList();
                }

    Tuesday, January 28, 2020 1:30 AM

All replies

  • User303363814 posted

    <div class="votecell post-layout--left"> <div class="js-voting-container grid fd-column ai-stretch gs4 fc-black-200" data-post-id="59941099">a bit rude <div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="0">to ask for free help</div> and make it so<div class="js-vote-count grid--cell fc-black-500 fs-title grid fd-column ai-center" itemprop="upvoteCount" data-value="0"> difficult to read</div> </div></div> <div class="postcell post-layout--right"><div class="post-text" itemprop="text">

    Maybe there is only one record?  You have not shown the source document

    Tuesday, January 28, 2020 10:16 PM