Question of SelectSingle Node



  • I'm learning to suck. Like, SelectSingleNode (HTML Agility Pack) get everything p or only SelectNodes? At this moment, I've got nothing but p and 1 <div> There's a violin. How can you rule it out? Thank you!

     var nodeText = document.DocumentNode.SelectSingleNode("/html/body/div[1]/div[2]/div[1]/article[1]");
    

    введите сюда описание изображения



  • Like, there's a few gigs. <p>♪ but we only need to find those inside the current ♪ article with attribution class="prose"

    var doc = new HtmlAgilityPack.HtmlDocument();
    doc.LoadHtml(@"
            <html><head /><body>
            <p>start></p>
            <article class='prose'><p>p1</p><p>p2</p></article>
            <p>end</p>
            </body></html>");
    

    foreach (var p in doc.DocumentNode.SelectNodes("//article[@class='prose']/p")) {
    Console.WriteLine(p.InnerText);
    }

    result

    p1
    p2




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2