Search code examples
phphtmlsimple-html-dom

Can't find anything using simplHtmlDom


On my host i scrape some differents website and everything was ok until yesterday. After change the host server they don't work anymore. This is the situation: I can get whole html of the page using simpleHtmlDom and Curl ,but cant fetch anything using find on it.

$str = file_get_contents($url);
$html = str_get_html($str);

if (!empty($html)) {
    echo "html is not null";
    if( $html->find('div[class="header"]' , 0)){
        echo "found";
    }
}

result:

html is not null

I checked it on different urls and different websites and result is same! Any suggestion?

Edit:

-tried to different way to get html:

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
$str = curl_exec($curl);

$html = str_get_html($str);

and

$html = file_get_html($url);

and

$html = new simple_html_dom(); 
$html->load($url);

result was same.

-Send mail to my hosting support and ask about any change on configuration that makes this happend. They said they changed the server of my host.

  • before face the problem, i didn't make any change on my scripts.

Solution

  • According to the hosting support, changing PHP version to 7.2 was the solution.Now all my scripts work perfectly.