Quantcast
Channel: htmlagilitypack Forum Rss Feed
Viewing all articles
Browse latest Browse all 655

New Post: Extract/Parse basic html table without headers

$
0
0

Figured it out! :)

 

Here's for the newbees like me :)

 

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HtmlAgilityPack;

namespace Phonex
{
    class Program
    {
        static void Main(string[] args)
        {
            String htmlFile = "..\\..\\phlist.html";
            
            HtmlDocument doc = new HtmlDocument();
            doc.Load(htmlFile);

            HtmlNodeCollection tables = doc.DocumentNode.SelectNodes("//table");
            HtmlNodeCollection rows = tables[0].SelectNodes(".//tr");

            string makeSpace = "\n\n\n\n\n";

            for (int i = 1; i < rows.Count; ++i)
            {
                HtmlNodeCollection cols = rows[i].SelectNodes(".//td");

                string phoneNumbers = cols[0].InnerText;
                string name = cols[1].InnerText;
                string city = cols[2].InnerText;
                string address = cols[3].InnerText;

                Console.WriteLine("PHONE NUMBER : " + phoneNumbers + "\n");
                Console.WriteLine("NAME         : " + name + "\n");
                Console.WriteLine("ADDRESS      : " + city + ", " + address + "\n");
                Console.WriteLine(makeSpace);

            }

        }
    }
}


Viewing all articles
Browse latest Browse all 655

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>