Html table on Html page - NO XML

I'm trying to grab data from an Html table on a website. No XML is involved.

<table id="e-cal-table" class="e-cal-table" width="100%">

<tr>

    <th>Date</th>

    <th>Time</th>

    <th>Currency</th>

    <th>Event</th>

    <th>Importance</th>

    <th>Actual</th>

    <th>Forecast</th>

    <th>Previous</th>

    <th>Notes</th>

</tr>

The following results in "Object reference not set to an instance of an object."

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml("http://www.example.com");

string table = doc.DocumentNode.SelectSingleNode("//table[@id='e-cal-table']").InnerText;

I'm at a loss as to how to identify the table for future parsing. Unfortunately, the only examples I've been able to find have to do with XML.

Answers


Your code works if you load your doc from string.

if you want to load it from an url use doc.Load(url); not doc.LoadHtml(htmlString);

--EDIT--

Sorry, my bad, doc.Load doesn't accept http You can use something like this

using (var wc = new WebClient())
{
    doc.LoadHtml(wc.DownloadString(url);
}

Your HTML above is missing a closing table tag. Could that be the problem? You could try Hpricot or Nokogiri.


Need Your Help

How to select specific elements using jquery from PHPs while loop generated elements?

javascript php jquery

First of all, I'm newbie to web programming. That said, I would really appreciate it if you could show me in the most understandable way to beginners.

How to ignore duplicate inserts with datamapper

ruby-on-rails ruby datamapper

I have a datamapper model that has a unique index on a property called name. I want to create new records when a name doesn't already exist and silently ignore attempts to create records with dupli...