【问题标题】:PHP Simple HTML DOM - file_get_contents(): SSL operation failed with code 1. OpenSSL Error messagesPHP 简单 HTML DOM - file_get_contents():SSL 操作失败,代码 1. OpenSSL 错误消息
【发布时间】:2022-01-11 23:58:38
【问题描述】:

我将使用 PHP Simple HTML DOM Parser 从另一个域中提取this page 的信息, 但不幸的是,当我使用file_get_htmlfile_get_content 时:

$html = file_get_html('https://aasood.com/a02s-64gb-4gb.html');

我收到此错误:

file_get_contents():SSL 操作失败,代码为 1。OpenSSL 错误消息:error:1416F086:SSLroutines:tls_process_server_certificate:certificate verify failed

我不拥有aasood.com,我无法更改其服务器。

请帮我解决这个问题

【问题讨论】:

    标签: php ssl simple-html-dom


    【解决方案1】:

    您可以在没有验证对等方的情况下使用 curl 来避免 SSL 问题,但最好修复 SSL 问题。

    $con = curl_init('https://aasood.com/a02s-64gb-4gb.html');
    curl_setopt($con, CURLOPT_CONNECTTIMEOUT, 2);
    curl_setopt($con, CURLOPT_TIMEOUT, 10);
    curl_setopt($con, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($con, CURLOPT_RETURNTRANSFER, true);
    $html = curl_exec($con);
    curl_close($con);
    

    【讨论】:

    • 感谢您的帮助但是当我按照您说的去做时:$con = curl_init('https://aasood.com/a02s-64gb-4gb.html'); curl_setopt($con, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($con, CURLOPT_TIMEOUT, 10); curl_setopt($con, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($con, CURLOPT_RETURNTRANSFER, true); $html = curl_exec($con); curl_close($con); if ($html !=''){ if ($html->find("meta[itemprop='price']")) { 我收到此错误:调用字符串上的成员函数 find()
    • 小心。查看 php.net 发现 file_get_html 不存在,它不是 PHP 函数。并且 file_get_contents 和 curl 返回字符串,而不是对象。要解析 HTML,您可以使用 DOMDocument::loadHTML (php.net/manual/en/domdocument.loadhtml.php),它属于 PHP 标准。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-02
    • 2021-05-14
    • 2015-04-27
    • 2020-05-12
    • 2016-09-07
    • 1970-01-01
    相关资源
    最近更新 更多