2017-05-15 3 views
-2

Uncaught Error: Call to a member function find() on string in C:\xampp\htdocs\dom\curldom.php:22 Stack trace: #0 {main} thrown in C:\xampp\htdocs\dom\curldom.php on line 22nicht erfasste Fehler: Rufen Sie auf eine Elementfunktion find() auf Zeichenfolge in PHP DOM kräuseln

geben diesen Fehler

  <?php 

     include('simple_html_dom.php'); 

     function getCode($url) 
     { 
      $ch=curl_init(); 
      curl_setopt($ch, CURLOPT_URL, $url); 
      curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36"); 
      curl_setopt($ch, CURLOPT_HEADER, 0); 
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false); 
      curl_setopt($ch, CURLOPT_REFERER, 'https://www.google.com/'); 
      $output = curl_exec($ch); 
      curl_close($ch); 
      $html = file_get_contents($output); 
      //return $output; 
     } 
     $url = 'http://www.amazon.in/Honor-6X-Grey-64GB/dp/B01LWZ14Z2/ref=sr_1_1?s=electronics&ie=UTF8&qid=1494825701&sr=1-1&keywords=honor+6x'; 
     $varc = getCode($url); 
     $cost = $varc->find('span[id=priceblock_saleprice]'); 
     // $price ='/<span id="priceblock_saleprice">/'; 
      // preg_match_all($price,$varc,$cost); 
     echo $cost; 

     ?> 
+0

Funktion finden nicht existiert. Auch das ist keine Klasse. Sie können nicht auf Funktionen wie diese zugreifen, wenn es sich nicht um eine PHP-Klasse handelt. – Akintunde007

+0

lol ...... // return $ output; Kommentar auf diese Zeile entfernen –

+0

Ich habe bereits tthat immer noch nicht funktioniert @BilalAhmed –

Antwort

-1

wird Ihnen Objekt überall, wenn nicht folgenden Code verwenden

Schaffung

anstatt $ cost = $ varc-> find ('span [id = priceblock_saleprice]');

Verwenden Sie $ cost = find ('span [id = priceblock_saleprice]');

+0

Aber jetzt in diesem Befehl $ cost = find ('span [ID = priceblock_saleprice] '); wo finden Funktion funktioniert? Im obigen Programm $ varc ist Extraktionscode von einer Seite und dann in diesem Schnipsel ($ cost = $ varc-> find ('span [id = priceblock_saleprice]');) find function find angegebene span id von varc .. –

Verwandte Themen