You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.6 KiB
43 lines
1.6 KiB
import requests
|
|
import json
|
|
import csv
|
|
import os
|
|
|
|
# UP主mid
|
|
mid = str(input("请输入up主的mid:"))
|
|
startPage = int(input("请输入起始页面:"))
|
|
finalPage = int(input("请输入终止页面:"))
|
|
|
|
# 请求头
|
|
headers = {
|
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) '
|
|
'AppleWebKit/537.36 (KHTML, like Gecko) '
|
|
'Chrome/58.0.3029.110 Safari/537.3'
|
|
}
|
|
|
|
# 创建CSV文件并写入表头
|
|
csv_file_name = 'video_links.csv'
|
|
with open(csv_file_name, 'w', newline='', encoding='utf-8') as csvfile:
|
|
writer = csv.writer(csvfile)
|
|
writer.writerow(['视频标题', '视频链接', '封面图片链接'])
|
|
|
|
# 获取前3页视频链接
|
|
for page in range(startPage, finalPage+1):
|
|
# 请求URL
|
|
url = 'https://api.bilibili.com/x/space/arc/search?mid=' \
|
|
+ mid + '&pn=' + str(page)
|
|
# 发送HTTP请求并解析返回的JSON格式数据
|
|
response = requests.get(url, headers=headers)
|
|
data = json.loads(response.text)
|
|
# 获取视频列表
|
|
video_list = data['data']['list']['vlist']
|
|
# 遍历视频列表,获取每个视频的标题、链接和封面图片
|
|
for video in video_list:
|
|
# 获取视频标题
|
|
title = video['title']
|
|
# 获取视频链接
|
|
video_url = 'https://www.bilibili.com/video/' + video['bvid']
|
|
# 获取视频封面图片链接
|
|
cover_url = video['pic']
|
|
# 将视频标题、链接和封面图片链接写入CSV文件中
|
|
writer.writerow([title, video_url, cover_url]) |