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.
Your code works if you load your doc from
string.if you want to load it from an url use
doc.Load(url);notdoc.LoadHtml(htmlString);–EDIT–
Sorry, my bad,
doc.Loaddoesn’t accepthttpYou can use something like this