【问题标题】:file_get_html() not working for the only webpagefile_get_html() 不适用于唯一的网页
【发布时间】:2019-01-14 12:12:46
【问题描述】:

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

我用另一个链接进行了测试,它可以工作,但是这个 url 不能正常工作。

我的代码是:

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

响应是一个空白页。

怎么了?

【问题讨论】:

    标签: simple-html-dom


    【解决方案1】:

    我解决了

     $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 照亮我的道路

    【讨论】:

      【解决方案2】:

      这只是一个猜测,但您有错误报告吗?

      开箱即用,这不适用于 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 Moved Permanently) - 要解决这个问题,您需要修改

      'follow_location' => false 
      

      'follow_location' => true
      

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-11-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-21
        • 2017-05-27
        • 1970-01-01
        相关资源
        最近更新 更多