2
我有一個名爲GrabUrTime的應用程序,它是一個時間表查看工具,從另一個網站,我的大學的網站空間獲取它的時間表。每個凌晨2點我運行一個腳本,使用解析器將所有時間表擦除並將其轉儲到我的數據庫中。PHP簡單的HTML DOM解析器:讓它循環,直到沒有錯誤
但今天uni的服務器運行不好,我的腳本不斷給我uni的服務器上的錯誤500,使腳本無法繼續運行。這是週期性的,並非總是如此。不過,我嘗試了幾次,它只是隨機發生,根本沒有任何模式。
因此,我想讓我的腳本來處理錯誤,並使其循環,直到它獲取數據。
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;
}
因此,我必須重寫整個代碼,因爲我使用HTML DOM解析器:P – 2012-02-14 09:23:39
@AnonozChong,我不這麼認爲,你能不能像沿着傳遞'grabtable'函數參數將成爲httpcode。然後在函數本身檢查httpcode是否正確,如果不正確,重新運行該函數或類似的東西? – martincarlin87 2012-02-14 09:30:35
哦......我錯過了手冊中的某些東西,對不起,我會嘗試你的代碼。任何想法如何使它成爲一個無限循環,直到我得到的HTML? – 2012-02-14 09:35:27