Керл дает мне пустую страницу на Yahoo.co.jp - PullRequest
0 голосов
/ 01 февраля 2019

Я пытаюсь получить имя продавца на странице аукциона Yahoo Japan, он хорошо работал до 1 года назад, а затем внезапно перестал работать.

приведенный ниже код пока только для возможностичтобы получить страницу аукциона.После этого я буду использовать pregmatch для получения необходимой информации.

Любая помощь будет более чем приветствоваться, я искал месяцы без какого-либо решения.Заранее спасибо.

    <html>
    <head><title>Get info</title>
    <!--meta http-equiv="Content-Type" content="text/plain;charset=utf-8"/-->
    </head>
    <body>

    <?php
    $link="https://page.auctions.yahoo.co.jp/jp/auction/c713387584";
    $agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0)         Gecko/20100101 Firefox/61.0";

    $fp = fopen("cookie.txt", "w");
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($curl, CURLOPT_URL, $link);
        curl_setopt($curl, CURLOPT_COOKIEJAR, "cookie.txt");
        curl_setopt($curl, CURLOPT_COOKIEFILE, "cookie.txt"); 
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($curl, CURLOPT_USERAGENT, $agent); 
        curl_setopt($curl, CURLOPT_VERBOSE, 1);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_AUTOREFERER, false);
        curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
        curl_setopt($curl, CURLOPT_HEADER, 0);

        $result = curl_exec ($curl);
        curl_close ($curl);
        print $result;


        fclose($fp);

    unlink("cookie.txt");
    ?>
    </body>
    </html>

`

1 Ответ

0 голосов
/ 01 февраля 2019

Скорее всего, ваша проблема вызвана слишком старым curl / openssl (или любым другим SSL-бэкендом, с которым ваш curl скомпилирован).

Это то, что я получаю из командной строки:

$ curl --silent --verbose >/dev/null --http1.1 --tls-max 1.1 --cookie-jar dummy.txt https://page.auctions.yahoo.co.jp/jp/auction/c713387
*   Trying 183.79.250.251...
* TCP_NODELAY set
* Connected to page.auctions.yahoo.co.jp (183.79.250.251) port 443 (#0)
...
* TLSv1.1 (OUT), TLS handshake, Client hello (1):
} [148 bytes data]
* OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to page.auctions.yahoo.co.jp:443 
* Closing connection 0

$ curl --silent --verbose >/dev/null --http1.1 --tls-max 1.2 --cookie-jar dummy.txt https://page.auctions.yahoo.co.jp/jp/auction/c713387 
*   Trying 183.79.250.251...
* TCP_NODELAY set
* Connected to page.auctions.yahoo.co.jp (183.79.250.251) port 443 (#0)
...
< HTTP/1.1 404 Not Found
< Cache-Control: private
< Content-Type: text/html; charset=utf-8
...
* Connection #0 to host page.auctions.yahoo.co.jp left intact

Сравните это с SO:

$ curl --silent --verbose >/dev/null --http1.1 --tls-max 1.1 https://stackoverflow.com/  
*   Trying 151.101.65.69...
* TCP_NODELAY set
* Connected to stackoverflow.com (151.101.65.69) port 443 (#0)
...
< HTTP/1.1 200 OK
< Cache-Control: private
< Content-Type: text/html; charset=utf-8
...
* Connection #0 to host stackoverflow.com left intact

Вкратце: yahoo.co.jp принимает только клиентов, которые говорят по крайней мере на TLS 1.2, SO допускает старых клиентов.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...