【问题标题】:PHP Curl but the HTML is Encrypted and SSL Certificate: unable to get local issuer certificatePHP Curl 但 HTML 已加密和 SSL 证书:无法获取本地颁发者证书
【发布时间】:2017-02-17 11:36:03
【问题描述】:

我想解析来自this site的HTML,我已经尝试使用了:

  1. file_get_contents
  2. Simple HTML DOM

但结果很糟糕:

然后我使用php html parser尝试PHP CURL,我发现错误是SSL证书问题:无法获取本地颁发者证书

搜索完答案后,我阅读了using curl to access https,并尝试使用那篇文章中的步骤获取证书但结果相同

问题是,为什么解析结果是这样的?现在,我不知道该怎么办:(

【问题讨论】:

    标签: html-parsing simple-html-dom php-curl


    【解决方案1】:

    页面使用 gzip 压缩。

    curl -k --compressed https://inaproc.lkpp.go.id/v3/daftar_lpse
    

    对于 PHP

    $ch = curl_init("https://inaproc.lkpp.go.id/v3/daftar_lpse");
    curl_setopt($ch, CURLOPT_ENCODING , "");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $output = curl_exec($ch);
    curl_close($ch);
    echo $output;
    

    【讨论】:

    • 啊,在阅读this之后,我一直想知道该站点是否使用gzip压缩。我已经尝试根据该设置使用gzip进行编码,但我不知道重点是将curl_setopt($ch, CURLOPT_ENCODING , ""); 设置为空白.. 呵呵,我的错,非常感谢你:)
    • 我在使用 xBTCe 公共 API 时遇到了同样的问题。非常感谢
    猜你喜欢
    • 2019-09-03
    • 2017-09-17
    • 2016-10-30
    • 1970-01-01
    • 2021-05-24
    • 2017-07-19
    相关资源
    最近更新 更多