2012-07-05 6 views
0
내가 (대표자가하는 같은) 웹 사이트에 얼마나 많은 이미지

Simple_html_dom : 대형 웹 사이트에서 이미지를 수신 할 수 없습니까?

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; 

} 

} 많은 웹 사이트에 대한

내가의 수를받을 URL에서 모든 이미지를 얻을 수 simple_html_dom.php을 사용하고

. 하지만 다음과 같은 오류가 나타납니다 웹 사이트 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 

가 어떻게이 오류를 prefend하고 읽을 수 있습니다 예를 들어 pinterest.com에 대한

답변

0

당신은 CURL 라이브러리를 사용할 수 있습니다 :

$url = $_POST['form_url']; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,$url); // set url to post to 
curl_setopt($ch, CURLOPT_FAILONERROR, 1); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable 
curl_setopt($ch, CURLOPT_TIMEOUT, 7); 
$resultHtml = curl_exec($ch); // run the whole process 
curl_close($ch); 

$html = new simple_html_dom(); 
$html->load($resultHtml); 
+0

나는 다음과 같은 오류가 나타날 수 경고 : curl_setopt()를 [function.curl - SETOPT] : 나는 $의 HTML을 위해서 var_dump 때 safe_mode가 활성화되거나 open_basedir을도 에 설정되어있는 경우 CURLOPT_FOLLOWLOCATION이 활성화 될 수 없다, 나는 얻을 출력되지만 보이지는 않습니다. – Stefan

+0

http://www.itemmized.com/test/test 에서 예제를 만들었습니다. 많은 사이트를 긁을 수 있지만 예를 들어 pinterest는 그가 긁기를 원하지 않는다는 것을 알 수 있습니다. 왜 함수가 작동하는지 모르겠습니다. | 위와 같이 컬을 사용할 때 예를 들어 내 사이트 (http://www.itemmized.com/test)를 더 이상 긁을 수 없습니다. 컬을 사용하지 않으면이 사이트를 긁을 수 있습니다. 아주 이상한 문제 ..... – Stefan

관련 문제