I am trying to parse a train schedule table from SEPTA train (Pennsyvania Train). So far I am able to get the correct table, but when I try to loop thought the table values I always get a empty variable no matter what I look for: TD/TR/Text.
What I am trying to do is get the: Scheduled Time, Estimated Time and Arrival Time from Station name. I try to search the stop name: 'Malvern' and get the schedule time.
This is how I got the main table:
//// Retrieve the DOM from a given URL
$html = file_get_html('http://trainview.septa.org/550');
$table = $html->find('table#scheduletable');
foreach($table as $MainTable)
{
echo $MainTable;
}
?>
Ok, now I have my table. If I try to do any ForEach using $table, I get a blank page (probably some PHP exception).
Here is what I have been trying to do without any success:
foreach($table->find('td') as $td) {
If($td == "Malvern") } // Found my row?
foreach($table->find('Malvern') as $td) {
}
foreach($table->find('td td') as $td) {
}
// Can I do this to get the TD values?
$table->find('td',0)->innertext // Station
$table->find('td',1)->innertext // Scheduled Time
$table->find('td',2)->innertext // Estimated Time
$table->find('td',3)->innertext // Arrival Time
This is how the table is formatted (HTML):
<table class="taglist" id="scheduletable">
<tbody>
<tr>
<th bgcolor="#c1dcfa" colspan="6"> <h2>
<div style="text-align: center;">Schedule for Train # 550 <br>
May 11, 2015 </div>
</h2></th>
</tr>
<tr valign="top" bgcolor="#aaeeee">
<th width="25%">Station</th>
<th width="5%"> </th>
<th><center>
Scheduled Time
</center></th>
<th><center>
Estimated Time
</center></th>
<th><center>
Arrival Time
</center></th>
</tr>
<tr>
<td>Thorndale</td>
<td></td>
<td>10:10 am</td>
<td></td>
<td>10:13 am</td>
<tr>
<td>Whitford</td>
<td></td>
<td>10:22 am</td>
<td></td>
<td>10:24 am</td>
<tr>
<td>Downingtown</td>
<td></td>
<td>10:17 am</td>
<td></td>
<td>12:00 am</td>
<tr>
<td>Exton</td>
<td></td>
<td>10:24 am</td>
<td></td>
<td>10:26 am</td>
<tr>
<td>Malvern</td>
<td></td>
<td>10:30 am</td>
<td></td>
<td>10:32 am</td>
<tr>
<td>Paoli</td>
<td></td>
<td>10:34 am</td>
<td></td>
<td>10:38 am</td>
</tbody>
</table>
Any help would be much appreciated.
I am reading all the HTML parser topics and I still cant figure out what is my problem here :(