1

I was using following code to scrap a web page it works normally on localhost but returns

require_once('advanced_html_dom.php');

$dom = file_get_html('http://exams.keralauniversity.ac.in/Login/index.php?reslt=1');

$rows = array();
foreach($dom->find('tr.Function_Text_Normal:has(td[3])') as $tr){
  $row['num'] = $tr->find('td[2]', 0)->text;
  $row['text'] = $tr->find('td[3]', 0)->text;
  $row['pdf'] = $tr->find('td[3] a', 0)->href;
  if(preg_match_all('/\d+/', $tr->parent->find('u', 0)->text, $m)){
    list($row['day'], $row['month'], $row['year']) = $m[0];
  }

  // uncomment next 2 lines to save the pdf
  // $filename = preg_replace('/.*\//', '', $row['pdf']);
  // file_put_contents($filename, file_get_contents($row['pdf']));
  $rows[] = $row;
}
var_dump($rows);

it shows following error when I inspected further

"Warning: Invalid argument supplied for foreach() in /home/a7944217/public_html/Results.php on line 477 "

var_dump this line $dom->find('tr.Function_Text_Normal:has(td[3])') and $dom returns null object when dumped shows this object(AdvancedHtmlDom)#1 (6) { ["xpath"]=> NULL ["root"]=> NULL ["doc"]=> RECURSION ["dom"]=> NULL ["node"]=> NULL ["is_text"]=> bool(false) }

file_get_html returns null .whats causing this weird behaviour works fine in localhost but not in live server Page link

vishuB
  • 4,173
  • 5
  • 31
  • 49
codefreaK
  • 3,584
  • 5
  • 34
  • 65

1 Answers1

2

You must set "allow_url_fopen" as TRUE in "php.ini" to allow accessing files via HTTP or FTP. Some hosting venders disable PHP's "allow_url_fopen" flag for security issues.

Or follow the post :Simple html dom file_get_html not working - is there any workaround?

Community
  • 1
  • 1