-1

My case is, I want to scrap a website, which is success, and I'm using PHP cURL. The problem start when I want to use the DOM Parser to get the content I want. Here is the warning came out:

the error image is here

And the code I use is here. Before this code, I scrap a website using cURL, it's working, but just this part got error :

include 'simple_html_dom.php';

//Here is where I scraping, no need to show it

$fp = fopen(dirname(__FILE__) . '/airpaz.html', 'w');

//$html contain the page I scrap

fwrite($fp, $html);
fclose($fp);

$html_content = file_get_contents(dirname(__FILE__) . '/airpaz.html');

echo $html_content;

$html2 = new simple_html_dom();
$html2->load_file($html_content);

Hope you guys can help, thanks

bobby I.
  • 101
  • 1
  • 11

2 Answers2

0

try this code

include 'simple_html_dom.php';

$html_content = file_get_html(dirname(__FILE__) . '/airpaz.html');

echo $html_content;

$html2 = new simple_html_dom();
$html2->load_file($html_content);
websynod
  • 26
  • 1
  • 2
Naumov
  • 1,167
  • 9
  • 22
  • It reply an error. This is the error: Warning: file_get_contents(270680): failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/simulasi/simple_html_dom.php on line 76 Warning: file_get_contents(): Filename cannot be empty in /Applications/XAMPP/xamppfiles/htdocs/simulasi/simple_html_dom.php on line 1097 – bobby I. Oct 03 '18 at 14:03
  • @bobbyI. I write error, remove `filesize` function from `file_get_html` and pass filename – Naumov Oct 03 '18 at 14:06
  • It's working, but still got 1 error. I'll update my question – bobby I. Oct 03 '18 at 14:08
0

It looks like you are trying to read a file 3 times:

$read_file = fread($fr, filesize(dirname(__FILE__) . '/airpaz.html'));

and:

$html_content = file_get_contents($read_file);

and:

$html2->load_file($html_content);

In the last two instances, instead of a file-name you pass html contents to the function so that will not work.

You should read the file only once and use string functions on the contents you receive. Or you open the url directly in $html2->load_file().

jeroen
  • 91,079
  • 21
  • 114
  • 132