1

htmlsimpledomでyoutubeの検索結果をスクレイピンングしようとしているのですが、以下のようなエラーが出てうまくいきません。。

詳しい方、ご教示ください。宜しくお願い致します。

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 /home/for815/www/test/simple_html_dom.php on line 76

Warning: file_get_contents(): Failed to enable crypto in /home/for815/www/test/simple_html_dom.php on line 76

Warning: file_get_contents(https://www.youtube.com/results?search_query=三菱電気&sp=EgIIBA%253D%253D): failed to open stream: operation failed in /home/for815/www/test/simple_html_dom.php on line 76

Fatal error: Call to a member function find() on boolean in /home/for815/www/test/youtube.php on line 39

コードは以下になります。

<?php
set_time_limit(0);
mb_language('ja');
mb_internal_encoding('UTF-8');
mb_regex_encoding('UTF-8');
header('Content-Type: text/html; charset=UTF-8');

require_once('config.php');

    try {
        $dbh = new PDO(DSN, DB_USER, DB_PASSWORD);
        $stmt = $dbh -> query("SET NAMES utf8;");
    } catch (PDOException $e) {
        echo $e->getMessage();
        exit;
    }



    include 'simple_html_dom.php';


    $html = file_get_html("https://www.youtube.com/results?search_query=panasonic&sp=EgIIBA%253D%253D");
    $html = mb_convert_encoding($html, 'utf8', 'auto');
    $dom = str_get_html($html);

    $get_result = $dom->find('p.num-results', 0)->plaintext;

    var_dump($get_result);
0

1 件の回答 1

1

該当コードを実行しているサーバーにインストールされているCA証明書が古くてエラーがでている可能性があります。

Redhat/CentOSであればopensslのパッケージにCA証明書が含まれているので最新の物にアップデートすると直るかもしれません。

sudo yum update openssl

OS X やその他の場合は 本家のこの回答が参考になります。
https://stackoverflow.com/questions/32019623/

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。