0

i use this code to Extract website https://billing.te.eg/Arabic/BillStatus.aspx?Acc=A4000917512

but i have a error Fatal error: Call to a member function find() on a non-object in index.php and what i want to Extract it between span elemant like <span id="SpanPhoneNumber" dir="ltr">02-26981106</span> or <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>';
omar dealo
  • 93
  • 9

1 Answers1

0

You forgot to use str_get_html() function on $html variable from sipmle_dom_html library:

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

when working with https pages you may also need to use inside your function:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
samrockon
  • 913
  • 3
  • 12
  • 17
  • thanx i put it like you said but it's same error `Call to a member function find() on a non-object in ` – omar dealo Apr 04 '15 at 18:26
  • do you think the problem from the website ? becouse i try now another link and working good . – omar dealo Apr 04 '15 at 18:27
  • Try $this->html->find – Alive to die - Anant Apr 04 '15 at 18:40
  • @anantkumarsingh i try it , show me this error `Fatal error: Using $this when not in object context` – omar dealo Apr 04 '15 at 18:48
  • Use DomDocument. for reference check link:-http://stackoverflow.com/questions/11567632/extracting-specific-data-from-a-web-page-using-php – Alive to die - Anant Apr 04 '15 at 18:54
  • @anantkumarsingh i try it and working good but with this site not work `https://billing.te.eg/Arabic/BillStatus.aspx?Acc=A4000917512` show me this error `Warning: file_get_contents(https://billing.te.eg/Arabic/BillStatus.aspx?Acc=A4000917512) [function.file-get-contents]: failed to open stream` – omar dealo Apr 04 '15 at 19:05
  • you may need to add following fields: curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); to work with https pages – samrockon Apr 04 '15 at 19:43
  • yeah it's working now as well , now how i can get data by element `span` and `id` like `02-26981106` or `19.30` – omar dealo Apr 04 '15 at 20:38