Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Using some of Jack Eker's code above and some code from Mark Gravell (<a href="https://stackoverflow.com/questions/655603/html-agility-pack-parsing-tables">see post here</a>) , I managed to come with a solution. This code snippet is used to obtain the public holidays for the year of 2012 in South Africa as of writing this article</p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Web; using System.Net; using HtmlAgilityPack; namespace WindowsFormsApplication { public partial class Form1 : Form { private DataTable dt; public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string htmlCode = ""; using (WebClient client = new WebClient()) { client.Headers.Add(HttpRequestHeader.UserAgent, "AvoidError"); htmlCode = client.DownloadString("http://www.info.gov.za/aboutsa/holidays.htm"); } HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(htmlCode); dt = new DataTable(); dt.Columns.Add("Name", typeof(string)); dt.Columns.Add("Value", typeof(string)); int count = 0; foreach (HtmlNode table in doc.DocumentNode.SelectNodes("//table")) { foreach (HtmlNode row in table.SelectNodes("tr")) { if (table.Id == "table2") { DataRow dr = dt.NewRow(); foreach (var cell in row.SelectNodes("td")) { if ((count % 2 == 0)) { dr["Name"] = cell.InnerText.Replace("&amp;nbsp;", " "); } else { dr["Value"] = cell.InnerText.Replace("&amp;nbsp;", " "); dt.Rows.Add(dr); } count++; } } } dataGridView1.DataSource = dt; } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload