Python_爬虫_简单实现bilibili小视频批量下载

非常简单的一个基础爬虫

import requests

count = 1

for page in range(0, 100):
    page = page * 10 + 1
    url = 'https://api.vc.bilibili.com/board/v1/ranking/top?page_size=10&next_offset='+ str(page) +'&tag=%E4%BB%8A%E6%97%A5%E7%83%AD%E9%97%A8&platform=pc'

    headers = {'User-Agent':'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0'}

    html = requests.get(url, headers=headers).json()

    response = html['data']['items']

    for i in response:
        ite = i['item']
        video_url = ite['video_playurl']

        video = requests.get(video_url, headers=headers).content
        with open('video/{}.mp4'.format(count),'wb') as f:
            count += 1
            f.write(video)

你可能感兴趣的:(Python_爬虫)