Python爬虫案例分享

Python爬取B站热门视频素材,附代源码,建议收藏

2021-10-25  本文已影响0人  Python案例教学
import requests

for page in range(0, 201, 20):
    url = f'https://cool.bilibili.com/x/co-create/material/list?material_type=19&ps=20&start_rank={page}&t=1634914151249'
    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36'
    }
    response = requests.get(url=url, headers=headers)
    materials = response.json()['data']['materials']
    for index in materials:
        title = index['title']
        video_url = index['videopre_url']
        video_content = requests.get(url=video_url, headers=headers).content
        with open('video\\' + title + '.mp4', mode='wb') as f:
            f.write(video_content)
            print(title)

上一篇 下一篇

猜你喜欢

热点阅读