-1
<div class="vcard-names-container py-3 js-sticky js-user-profile-sticky-fields " style="position: static;">
  <h1 class="vcard-names">
    <span class="vcard-fullname d-block" itemprop="name">Name 001</span>
    <span class="vcard-username d-block" itemprop="additionalName">Name 002</span>
  </h1>
</div>

Hello, I would like to know how to retrieve the names of this structure ('Name 001' and 'Name 002') I did several tests but I could not parse these values, how do I achieve this?

(Note: Sorry for my bad english)

  • Duplicate shows how to get attribute as you've asked, but based on body of the post you likely need text of an element rather that value of attribute of an element. In this case http://stackoverflow.com/questions/4358696/how-to-get-the-contents-of-a-html-element-using-htmlagilitypack-in-c would be the answer. – Alexei Levenkov Jan 16 '17 at 02:05

2 Answers2

0

You can use XPath to query the document nodes to find the nodes you are looking for:

static void Main(string[] args)
{
    var html = @"<div class=""vcard - names - container py - 3 js - sticky js - user - profile - sticky - fields "" style=""position: static; "">
           < h1 class=""vcard-names"">
            <span class=""vcard-fullname d-block"" itemprop=""name"">Name 001</span>
            <span class=""vcard-username d-block"" itemprop=""additionalName"">Name 002</span>
          </h1>
        </div>";

    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
    doc.LoadHtml(html);

    var names = doc.DocumentNode.SelectNodes("//span").Select(x => x.InnerText);
    foreach (var name in names)
    {
        Console.WriteLine(name);
    }
    Console.ReadLine();
}
John Koerner
  • 37,428
  • 8
  • 84
  • 134
0

This might do the trick for you

HtmlDocument doc = new HtmlDocument();
doc.Load(YourHTMLFile);
foreach(HtmlNode Spans in doc.DocumentNode.SelectNodes("//span"))
{
    Console.WriteLine(Spans.InnerText);
}
Mohit S
  • 13,723
  • 6
  • 34
  • 69