2016-12-18 1 views
0

J'essaie de gratter kickasstorrents avec simple html dom, mais je reçois une erreur et je n'ai même pas encore commencé. J'ai suivi quelques tutoriels html simples et j'ai mis en place mon URL et en utilisant curl.Essayer de gratter kickasstorrents avec simple html dom

code est le suivant:

<?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; 
?> 

Je reçois les erreurs

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

Que dois-je faire le mal? Merci.

+0

Je peux confirmer que self-html-dom s'étouffe sur cette page. Vous pouvez [essayer ceci en remplacement] (https://github.com/monkeysuffrage/advanced_html_dom). – pguardiario

Répondre

0

Simple_html_dom est une classe. Dans cette classe il peut y avoir un appel de fonction, clear ou c'est dans la classe Simple_html_dom_node. Mais en simple html dom, vous devez utiliser la classe simple_html_dom.

@Hassaan, est correct. file_get_contents est une fonction php native, vous devez créer un objet de classe simple_html_dom. Comme,

$html = new simple_html_dom(); 

Et utilisez ce code ci-dessous.

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(); 

Eh bien, il y a beaucoup d'erreurs dans votre code, alors je vous dis simplement comment vous pouvez faire cela. Si une explication est nécessaire, veuillez commenter ci-dessous cette réponse. Je vais.

0

file_get_contents est la fonction intégrée de PHP. Dom simple html, vous pouvez utiliser file_get_html

Remplacer

$kat = file_get_contents($html); 

avec

$kat = file_get_html($html); 

Pourquoi vous retournez $ret; comme votre code dans votre question. Il n'y a pas $ret variable vous fonctionnez scrap_kat()

Vous pouvez retourner $kat au lieu de $ret et ne pas unset($kat);

+0

J'ai essayé une approche différente. –

+0

J'ai essayé une approche différente, si vous allez à: http://pastebin.com/CD8M9eiF et voyez ... Maintenant, je reçois: C: \ wamp64 \ www \ index.php: 40: null lors d'un var_dump, donc rien ne passe ... des idées? –