爱意满满的作品展示区。
Liulang007

PHP 爬虫 获取 Bilibili 视频封面图

  •  
  •   Liulang007 · Jan 30, 2019 · 2257 views
    This topic created in 2691 days ago, the information mentioned may be changed or developed.
    <?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;
    
    ?>
    

    PHP 爬虫 获取 Bilibili 视频封面图

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

    Liulang007
        1
    Liulang007  
    OP
       Jan 31, 2019
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2745 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 06:03 · PVG 14:03 · LAX 23:03 · JFK 02:03
    ♥ Do have faith in what you're doing.