title: How to extract data from webpage using C#
body: <p>I'm trying to extract text from this HTML tag</p>
  <pre class="lang-html prettyprint-override"><code>&lt;span id=&quot;example1&quot;&gt;sometext&lt;/span&gt;
  </code></pre>
  <p>And I have this code:</p>
  <pre class="lang-cs prettyprint-override"><code>using System;
  using System.Net;
  using HtmlAgilityPack;
  
  namespace GC_data_console
  {
      class Program
      {
          public static void Main(string[] args)
          {           
              using (var client = new WebClient())
              {
                  // Download the HTML
                  string html =
                      client.DownloadString(&quot;https://www.requestedwebsite.com&quot;);
                  HtmlDocument doc = new HtmlDocument();
                  doc.LoadHtml(html);
                  foreach(HtmlNode link in
                          doc.DocumentNode.SelectNodes(&quot;//span&quot;))
                  {
                      HtmlAttribute href = link.Attributes[&quot;id='example1'&quot;];
                      if (href != null)
                      {
                          Console.WriteLine(href.Value.ToString());
                          Console.ReadLine();
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  <p>But I am still not getting the text <code>sometext</code>.
  But if I insert:</p>
  <pre class="lang-cs prettyprint-override"><code>HtmlAttribute href = link.Attributes[&quot;id&quot;];
  </code></pre>
  <p>I'll get all the IDs names. What am I doing wrong?</p>