file_get_html()不适用于唯一的网页

时间:2019-01-14 12:12:46

标签: simple-html-dom

我想调用一个简单的DOM文件

我使用其他链接进行了测试,并且可以正常工作,但是使用此网址无法正常工作。

我的代码是:

 $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;
 }

“响应”为空白页面。

怎么了?

2 个答案:

答案 0 :(得分:0)

这只是一个猜测,但是您有关于错误报告的信息吗?

开箱即用,这不适用于simple-html-dom库:

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

可以找到针对此问题的解决方法here-正确地完成此操作后,我仍然得到空白页,这是由于答案错误(永久性地移动了301)-为此,您需要进行修改

'follow_location' => false 

'follow_location' => true

因此,现在我们获得了正确的网站内容-您可以将选择器修改为$html->find('#ctl00_ContentPlaceHolder1_gvFyO');,这将找到id=ctl00_ContentPlaceHolder1_gvFyO的所有元素-请参见documentation作为参考。

答案 1 :(得分:0)

我解决了

 $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;

}

感谢@ maio290点亮我的路