b站python up主_python爬取B站up主全部视频封面

B站up主的点赞投币转发等信息,以及弹幕文件、评论文件等等都可以调用特定的API接口来获得。

有很多简易的小程序或者网站可以获得某个视频的封面,但是如果想要一键提取所有的视频封面,最好还是通过写代码来爬取效果更好。

1.在同级目录创建一个名为image的文件夹

2.运行下面的代码

import requests

import urllib

x = 1

def get_images(url):

headers = {'Usar-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36'}

res = requests.get(url,headers=headers,timeout=(5,5))

for video in res.json()['data']['list']['vlist']:

global x

urllib.request.urlretrieve("http:"+video['pic'],'image\%s.jpg'%x)

print ("Downloading image No.{}".format(x));

x += 1

for page in range(1,10):

url = 'https://api.bilibili.com/x/space/arc/search?mid=485599712&ps=30&tid=0&pn={}&keyword=&order=pubdate&jsonp=jsonp'.format(page)

get_images(url)

3.要爬取不同的up主的视频封面修改的信息是url里面的mid=后面的一串数字,替换成对应up主的UID即可。

4.运行效果如下

……

……

Downloading image No.67

Downloading image No.68

Downloading image No.69

Downloading image No.70

Downloading image No.71

Downloading image No.72

Downloading image No.73

Downloading image No.74

Downloading image No.75

Downloading image No.76

Downloading image No.77

14eeeb1d05a2

在这里插入图片描述

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值