私はsimple_html_dom.phpを使用してURLからすべての画像を取得しています(pinterestのように)
if($_POST['submit']) {
$url = $_POST['form_url'];
$html = file_get_html($url);
$count = 0;
$goodfiles = array();
if($html && is_object($html) && isset($html->nodes)){
foreach($html->find('img') as $img){
$count++;
}
}else{
echo "failed";
}
echo $count;
}
}
多くのウェブサイトで、ウェブサイトにある画像の数を受け取ります。しかし、たとえば、ウェブサイトpinterest.comの場合、次のエラーが表示されます。
Warning: file_get_contents(http://www.pinterest.com) [function.file-get-contents]: failed to open stream: Connection timed out in /home/vyrxkian/domains/bblablabla/include/simple_html_dom.php on line 70
failed 0
さらにエラーを指定すると、次のようになります。
Warning: file_get_contents(http://www.pinterest.com) [function.file-get-contents]: failed to open stream: Connection timed out in /home/vyrxkian/domains/bblablabla/include/simple_html_dom.php on line 70
Fatal error: Call to a member function find() on a non-object in /home/vyrxkian/domains/bblablabla.php on line 30
どうすればこのエラーのふりをして、たとえばpinterest.comを読むことができますか