在抓取之前,我使用Curl方法检查HTTP响应。
foreach($URls as $URL){
if($response($URL)==200){
$html= new 'Htmldom($URL);}}
但有时(SERVER响应404),循环停止,我希望它继续(移动到下一个)即使其中一个页面返回为失败。
我正在使用Laravel Yanqi HTMLDom Parser
我认为您必须使用try{}catch{}
块才能继续循环过程。下面是这个例子。
foreach($URls as $URL) {
try{
if($response($URL)==200) {
$html= new 'Htmldom($URL);
}
} catch('Exception $e) {
// can catch exception
}
}
我想这会对你有所帮助。
添加其他:
foreach($URls as $URL){
if($response($URL)==200){
$html= new 'Htmldom($URL);
} else {
continue;
}
}