zoukankan      html  css  js  c++  java
  • PHP爬虫 获取 Bilibili 视频封面图

    原文链接

    [PHP] 纯文本查看 复制代码
    01
    02
    03
    04
    05
    06
    07
    08
    09
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    <?php
     
    function curl($url)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5000);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4'));
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_REDIR_PROTOCOLS, -1);
        $contents = curl_exec($ch);
        curl_close($ch);
        return $contents;
    }
     
    function getBilibiliAVCover($avNum)
    {
        $contents = curl('https://m.bilibili.com/video/' . $avNum . '.html');
        preg_match("~"pic":"(.*?)"~", $contents, $matches);
        if (count($matches) == 0) {
            echo '没有找到相应的图片,请换个 av 号试一下。';
            exit;
        }
        $img = file_get_contents($matches[1]);
        file_put_contents('default.png', $img);
        echo '<img src="default.png">';
    }
     
    getBilibiliAVCover('av417622790');
    exit;
     
    ?>


    演示地址:https://www.liulangboy.com/tools/01/get-bilibili-cover.php

    default.png (274.37 KB, 下载次数: 6)

     

    default.png
     

     

  • 相关阅读:
    668. Kth Smallest Number in Multiplication Table
    658. Find K Closest Elements
    483. Smallest Good Base
    475. Heaters
    454. 4Sum II
    441. Arranging Coins
    436. Find Right Interval
    410. Split Array Largest Sum
    392. Is Subsequence
    378. Kth Smallest Element in a Sorted Matrix
  • 原文地址:https://www.cnblogs.com/jscs/p/13628353.html
Copyright © 2011-2022 走看看