How to Parse HTML Table

Topics: Developer Forum
Jun 19, 2010 at 9:56 PM
Edited Jun 19, 2010 at 10:29 PM

I have not used Html Agility Pack.  Wondering if someone could help me with the syntax to parse through a html table.  I have pasted the table below.  Essentially, I need to grab the values under the <th> tags.  For example, in the first row I need to grab "Emission Select Component Ltd Wty", "03/17/2006", "10 MI", "03/17/2014", "80,010 MI".  I would need to grab all of the rows of information.  Perhaps, store the values in a collection or array to be passed to a method, which will save the data.  The table below is just a snippet of the html page.  I would first need to find the table in the page and then just extract the values in the table.  The key tag to get to the table section is the first <td> tag containing "Applicable Warranties".

<div id="warranties">
<table class="" width="100%">
<tr>
<td colspan="3" class="h02 left">Applicable Warranties</td>
<td colspan="4" class="right">Valid warranties are highlighted</td>
</tr>
<tr class="gridHeader">
<th class="center">Valid</th>
<th class="center">Description</th>
<th class="center">Start Date</th>
<th class="center">Effective Odometer</th>
<th class="center">End Date</th>
<th class="center">End Odometer</th>
</tr>
<tr >
<td class="center black"></td>
<td class="center black">Emission Select Component Ltd Wty</td>
<td class="center black">03/17/2006</td>
<td class="center black">10&nbsp;MI</td>
<td class="center black">03/17/2014</td>
<td class="center black">80,010&nbsp;MI</td>
</tr>
<tr >
<td class="center black"></td>
<td class="center black">Bumper to Bumper Limited Warranty</td>
<td class="center black">03/17/2006</td>
<td class="center black">10&nbsp;MI</td>
<td class="center black">03/17/2010</td>
<td class="center black">50,010&nbsp;MI</td>
</tr>
<tr >
<td class="center black"></td>
<td class="center black">Corrosion Limited Warranty</td>
<td class="center black">03/17/2006</td>
<td class="center black">10&nbsp;MI</td>
<td class="center black">03/17/2012</td>
<td class="center black">Unlimited</td>
</tr>
</table>
</div>