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.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
import requests
import json
# 定义API的URL地址
url = ' https://api.bilibili.com/x/web-interface/wbi/search/type '
# 设置请求头, 包括用户代理和Cookie信息
headers = {
' user-agent ' : ' Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0 ' ,
' cookie ' : ' buvid3=C1C1F447-BE4B-207B-2957-83F2A71759A059661infoc; b_nut=1702126959; i-wanna-go-back=-1; b_ut=7; _uuid=A1D1B10B10-2CF10-E524-9184-1071108C67B4E1064260infoc; enable_web_push=DISABLE; buvid4=5317C42D-F53F-8ADA-D1A4-10ED5A8CF36360134-023120913-; rpdid=|(u)luk)~u|l0J \' u~|kku|YkJ; buvid_fp_plain=undefined; DedeUserID=503618475; DedeUserID__ckMd5=0191b9f7decce9ef; header_theme_version=CLOSE; CURRENT_FNVAL=4048; PVID=1; FEED_LIVE_VERSION=V_DYN_LIVING_UP; CURRENT_QUALITY=80; fingerprint=494d7e3b36301c3a79f8e9874737c192; buvid_fp=494d7e3b36301c3a79f8e9874737c192; home_feed_column=5; browser_resolution=1528-738; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjY3NDUwMjAsImlhdCI6MTcyNjQ4NTc2MCwicGx0IjotMX0.eMwpvZWiFlweKrmxccHjMI_iLBtXhkjCTiGo47ZzSYo; bili_ticket_expires=1726744960; SESSDATA=83336e6b % 2C1742037821 % 2C360f4 % 2A92CjAH43lV7rav7Ckt21G7pofPKHP90eY8UWnZbAt07TaYyt5UEqN4ePWE_NCr5lh3vfYSVkJoSzBzNldWOFZWUEZJZ2Y3YnY0dXZZWmllcXhUMlpDT1RhVk4xYldiZ3NRMG9XVnZpUnk4SWN6UHNLUUx3cDBsNkxUMHRHajZ2WGlkak5MVUFTX1RBIIEC; bili_jct=9406239f74c298cb8651019f52e42523; sid=7uv2rrbi; b_lsid=8BA3B5CC_191FF98AD70; bp_t_offset_503618475=978100787878035456; bsource=search_google '
}
# 遍历页码
for num in range ( 1 , 7 ) :
params = {
' search_type ' : ' video ' ,
' page ' : num ,
' keyword ' : ' 2024巴黎奥运会 ' ,
' page_size ' : ' 50 '
}
response = requests . get ( url , headers = headers , params = params )
response . encoding = ' utf-8 '
# 解析JSON响应
data = json . loads ( response . text )
# 提取视频的id
for video in data [ ' data ' ] [ ' result ' ] :
id = video [ ' id ' ]
print ( id )
print ( " 完成id提取 " )