2015-04-04 5 views
0

я использую этот код для извлечения вебсайту https://billing.te.eg/Arabic/BillStatus.aspx?Acc=A4000917512Извлечение сайта HTML данных с помощью PHP

, но у меня есть ошибка Fatal error: Call to a member function find() on a non-object in index.php и то, что я хочу, чтобы извлечь его между поверочного elemant как <span id="SpanPhoneNumber" dir="ltr">02-26981106</span> или <span id="SpanCurrentBalance">19.30</span>

include_once("simple_html_dom.php"); 
//use curl to get html content 
function getHTML($url,$timeout) 
{ 
     $ch = curl_init($url); // initialize curl with given url 
     curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); // set useragent 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // write the response to a variable 
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects if any 
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // max. seconds to execute 
     curl_setopt($ch, CURLOPT_FAILONERROR, 1); // stop when it encounters an error 
     return @curl_exec($ch); 
} 
$html=getHTML("https://billing.te.eg/Arabic/BillStatus.aspx?Acc=A4000917512",10); 
// Find all images on webpage 
foreach($html->find("img") as $element) 
echo $element->src . '<br>'; 

// Find all links on webpage 
foreach($html->find("a") as $element) 
echo $element->href . '<br>'; 

ответ

0

Вы забыли использовать str_get_html() функция на переменной $ html из библиотеки sipmle_dom_html:

$response=getHTML("https://billing.te.eg/Arabic/BillStatus.aspx?Acc=A4000917512",10); 
$html = str_get_html($response); 

при работе с HTTPS-страниц, вы можете также необходимо использовать внутри функции:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
+0

Thanx я поставил его, как вы сказали, но это та же ошибка 'вызов функции члена находке() на не-объект в ' –

+0

, как вы думаете, проблема с сайта? потому что я пробую теперь еще одну ссылку и работаю хорошо. –

+0

Попробуйте $ this-> html-> find –

Смежные вопросы