fakasmile1
fakasmile1

Reputation: 69

file_get_html() not working for the only webpage

I want to call a simple DOM file

I tested with another links and it works, but with this url it's not working.

My code is:

 $bnadatos = file_get_html("http://www.rofex.com.ar/cem/FyO.aspx");

 foreach($bnadatos->find('[@id="ctl00_ContentPlaceHolder1_gvFyO"]') as $i){
     echo "datos:";
     echo $i->innertext;
 }

Response is a blank page.

What's wrong?

Upvotes: 2

Views: 1095

Answers (2)

fakasmile1
fakasmile1

Reputation: 69

i solved with

 $arrContextOptions=array(
    "ssl"=>array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);  

$response = file_get_html("https://www.rofex.com.ar/cem/FyO.aspx", false, stream_context_create($arrContextOptions));


foreach($response->find('[@id="ctl00_gvwDDF"]/tbody/tr[2]/td[2]') as $i){

  echo $i->innertext;

}

thank you @maio290 for light my road

Upvotes: 1

maio290
maio290

Reputation: 6732

This is just a guess, but do you have your error reporting on?

Out of the box, this is not working with the simple-html-dom library:

Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in /var/www/html/dom.php on line 83

Warning: file_get_contents(): Failed to enable crypto in /var/www/html/dom.php on line 83

Warning: file_get_contents(http://www.rofex.com.ar/cem/FyO.aspx): failed to open stream: operation failed in /var/www/html/dom.php on line 83

Fatal error: Call to a member function find() on boolean in /var/www/html/test.php on line 11

A fix for this can be found here - with that in place, I still get a blank page, which is due to a wrong answer (301 Moved Permanently) - for this to fix, you need to modify

'follow_location' => false 

to

'follow_location' => true

so, now we get the proper site content - you can modify the selector to $html->find('#ctl00_ContentPlaceHolder1_gvFyO'); this will find all element which id=ctl00_ContentPlaceHolder1_gvFyO - see the documentation as reference.

Upvotes: 0

Related Questions