I had an app called GrabUrTime, it’s a timetable viewing utility that get its timetables from another site, my university’s webspace. Every 2am I run a script that scrapes all the timetables using the parser and dump it into my database.
But today the uni’s server isn’t running well and my script keeps on giving me error 500 on uni’s server, making the script cannot continue to run. It’s periodic, not always. However I tried a few times and it just occurs randomly, no pattern at all.
Hence I want to make my script to handle the error and make it loop until it gets the data.
function grabtable($intakecode, $week) {
$html = file_get_html("http://webspace.apiit.edu.my/schedule/intakeview_intake.jsp?Intake1=".$intakecode."&Week=" . $week);
$dumb = $html->find('table[border=1] tr');
$thatarray = array();
for ($i=1; $i < sizeof($dumb);++$i){
$arow = $html->find('table[border=1] tr', $i);
$date = $arow->find('td font', 0)->innertext;
$time = $arow->find('td font', 1)->innertext;
$room = $arow->find('td font', 2)->innertext;
$loca = $arow->find('td font', 3)->innertext;
$modu = $arow->find('td font', 4)->innertext;
$lect = $arow->find('td font', 5)->innertext;
$anarray = array($date, $time, $room, $loca, $modu, $lect);
$thatarray[$i] = $anarray;
//echo "arraylol";
}
//echo serialize($tablearray)."<br/>";
$html->clear();
return $thatarray;
}
try something like this:
usage
It might not plug neatly into your code as it is but I’m sure it can help with a little re-factoring to suit your existing code structure.