|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
爬取B站综合热门
网址为 https://www.bilibili.com/v/popular/all
- import requests # 网络请求模块
- import time # 时间模块
- import random # 随机模块
- # 哔哩哔哩
- json_url = 'https://api.bilibili.com/x/web-interface/popular?ps=20&pn={page}'
- class Crawl():
- def __init__(self):
- # 创建头部信息
- self.headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0'}
- def get_json(self,json_url):
- response = requests.get(json_url, headers=self.headers)
- # 判断请求是否成功
- if response.status_code == 200:
- return response.json() # 返回json信息
- else:
- print('获取json信息的请求没有成功!')
- if __name__ == '__main__':
- c = Crawl() # 创建爬虫类对象
- for page in range(1,12): #页码
- json = c.get_json(json_url.format(page=page))
- infos = json['data']['list']# 信息集
- for info in infos: # 遍历信息
- title = info['title'] # 视频标题
- video_url = info['short_link'] # 视频地址
- print(title, video_url) # 打印提取的视频标题与视频地址
- time.sleep(random.randint(2,4)) # 随机产生获取json请求的间隔时间
复制代码
寻个大佬 求教一下接下去的视频链接下载! 我没找到mp4格式
|
|