我正在使用 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