2016-12-18 5 views
0

간단한 html dom을 사용하여 kickasstorrents를 긁어 내려고했지만 오류가 발생했으며 아직 시작하지 않았습니다. 몇 가지 간단한 html 자습서를 따랐고 URL을 설정하고 말풍선을 사용했습니다. 간단한 html dom을 사용하여 kickasstorrents를 긁어 내려고 시도

<?php 
require('inc/config.php'); 
include_once('inc/simple_html_dom.php'); 

function scrap_kat() { 

// initialize curl 
$html = 'http://katcr.to/new/'; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $html); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); 
$ip=rand(0,255).'.'.rand(0,255).'.'.rand(0,255).'.'.rand(0,255); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array("REMOTE_ADDR: $ip", "HTTP_X_FORWARDED_FOR: $ip")); 
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/".rand(3,5).".".rand(0,3)." (Windows NT ".rand(3,5).".".rand(0,2)."; rv:2.0.1) Gecko/20100101 Firefox/".rand(3,5).".0.1"); 
$html2 = curl_exec($ch); 
if($html2 === false) 
{ 
    echo 'Curl error: ' . curl_error($ch); 
} 
else 
{ 
    // create HTML DOM 
    $kat = file_get_contents($html); 
} 
curl_close($ch); 

// scripting starts 




// clean up memory 
$kat->clear(); 
unset($kat); 
// return information 
return $ret; 

} 
$ret = scrap_kat(); 
echo $ret; 
?> 

내가

Fatal error: Call to a member function clear() on resource in C:\wamp64\www\index.php on line 36

내가 뭘 잘못 않는 오류가 다음과 같이

코드는? 감사합니다. .

+0

그 페이지에서 단순 html-dom 쵸크를 확인할 수 있습니다. [대체 제품으로 사용해보십시오] (https://github.com/monkeysuffrage/advanced_html_dom). – pguardiario

답변

0

Simple_html_dom이 클래스 할 수 scrap_kat()

을 기능에 어떤 변수 $ret 없습니다. 이 클래스에는 Simple_html_dom_node 클래스에있는 함수 호출이있을 수 있습니다. 하지만 간단한 HTML DOM에서는 simple_html_dom 클래스를 사용해야합니다.

@Hassaan, 맞습니다. file_get_contents는 기본 PHP 함수이므로 simple_html_dom 클래스의 객체를 만들어야합니다. 좋아요,

$html = new simple_html_dom(); 

그리고 아래 코드를 사용하십시오.

function scrap_kat() { 
$url = 'http://katcr.to/new/'; 
// $timeout= 120; 
# create object 
$html = new simple_html_dom(); 
#### CURL BLOCK #### 
$curl = curl_init(); 
curl_setopt($curl, CURLOPT_URL, $url); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/".rand(3,5).".".rand(0,3)." (Windows NT ".rand(3,5).".".rand(0,2)."; rv:2.0.1) Gecko/20100101 Firefox/".rand(3,5).".0.1"); 
//curl_setopt($curl, CURLOPT_TIMEOUT, $timeout); 
$ip=rand(0,255).'.'.rand(0,255).'.'.rand(0,255).'.'.rand(0,255); 
curl_setopt($curl, CURLOPT_HTTPHEADER, array("REMOTE_ADDR: $ip", "HTTP_X_FORWARDED_FOR: $ip")); 
$content = curl_exec($curl); 
curl_close($curl); 
# note the variable change. 
# load the curl string into the object. 
$html->load($content); 
//echo $ip; 
#### END CURL BLOCK #### 
print_r($html->find('a')); 
// clean up memory 
$html->clear(); 
unset($html); 
} 
scrap_kat(); 

음, 코드에 오류가 많아서 어떻게 처리 할 수 ​​있는지 알려주고 있습니다. 설명이 필요한 경우이 대답 아래에 의견을 말하십시오. 나는 할 것이다.

0

file_get_contents은 PHP의 기본 기능입니다. 간단한 HTML DOM을 위해 당신은 당신이 당신의 질문에 코드로 $ret;를 반환하는 이유는 file_get_html

$kat = file_get_html($html); 

$kat = file_get_contents($html); 

를 교체 사용할 수 있습니다. 당신은 당신이 $kat 대신 $ret을 반환하지 unset($kat);

+0

다른 접근 방식을 시도했습니다. –

+0

당신이 갈 경우 다른 접근 방식을 시도 : http://pastebin.com/CD8M9eiF 및 참조 ... 이제 얻을 : C : \ wamp64 \ www \ index.php : 40 : var_dump 할 때 null, 그래서 아무것도 얻지 못합니다 ... 어떤 아이디어? –