Parse html table using PHP Simple HTML DOM Parser -
i trying parse train schedule table septa train (pennsyvania train). far able correct table, when try loop thought table values empty variable no matter for: td/tr/text.
what trying the: scheduled time, estimated time , arrival time station name. try search stop name: 'malvern' , schedule time.
this how got main table:
//// retrieve dom given url $html = file_get_html('http://trainview.septa.org/550'); $table = $html->find('table#scheduletable'); foreach($table $maintable) { echo $maintable; } ?>
ok, have table. if try foreach using $table, blank page (probably php exception).
here have been trying without success:
foreach($table->find('td') $td) { if($td == "malvern") } // found row? foreach($table->find('malvern') $td) { } foreach($table->find('td td') $td) { } // can 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 how table formatted (html):
<table class="taglist" id="scheduletable"> <tbody> <tr> <th bgcolor="#c1dcfa" colspan="6"> <h2> <div style="text-align: center;">schedule 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 appreciated.
i reading html parser topics , still cant figure out problem here :(
Comments
Post a Comment