diff --git a/python.py b/python.py new file mode 100644 index 0000000..7a4abb8 --- /dev/null +++ b/python.py @@ -0,0 +1,43 @@ +import requests + +def GetResponse(url, data): + """发送请求 + - url: 请求网址 + - data: 请求参数 + """ + # 模拟游览器 + headers = { + # Cookie 用户信息,常用于检测是否有登陆账号 + "Cookie": "b_nut=1655303638; CURRENT_BLACKGAP=0; i-wanna-go-back=-1; buvid_fp_plain=undefined; buvid3=136172B5-8F7E-42EF-90C5-2D4A04147EE8167644infoc; LIVE_BUVID=AUTO3016558277732131; is-2022-channel=1; DedeUserID=17012171; DedeUserID__ckMd5=f518907167c48789; buvid4=88DCF3D1-502C-06D9-BF49-B7E4F0A0519315466-022061522-P1wwgn5lZ%2FpHMTaSvipifA%3D%3D; rpdid=|(JlRYJ~Ykl)0J'u~|JulJkJm; b_ut=5; FEED_LIVE_VERSION=V_HEADER_LIVE_NO_POP; _uuid=10525FA4C-8522-AFCC-210B4-19DE77B6FC8C66067infoc; enable_web_push=DISABLE; header_theme_version=CLOSE; CURRENT_FNVAL=16; fingerprint=913be879852fe07606cd36fdc205d010; CURRENT_QUALITY=116; home_feed_column=5; SESSDATA=02073d74%2C1741791214%2C27f68%2A92CjCmgDH-jkOm_SxUtVJFNLtOJeIP0b8hsAHsHrrFFZfOBISh6cYei3G1uSHUdK8BsdASVmRNelVZU29kZ2tWTk5iY05vWXJnSk9ZcVF5d0RmOUdKbGVWVEg2dmFGMXZsVmNEMUNRVnR0cUxyNXdWWlh5eXN6NFBPakh2M1puVjYzUFJ4T2cyWVBnIIEC; bili_jct=f29317e8f0203187c9bcec98ac9bbd30; PVID=2; browser_resolution=1707-837; buvid_fp=913be879852fe07606cd36fdc205d010; bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjY1ODE3NTksImlhdCI6MTcyNjMyMjQ5OSwicGx0IjotMX0.gM_SG7dtVNHO6JWzjJQb9TKfMdYUCQCc5kwBCvwvLTg; bili_ticket_expires=1726581699; b_lsid=A381C4D2_191F9C4B633; sid=8hmdz3e3; bp_t_offset_17012171=977684498172870656", + # User-Agent 用户代理,表示游览器基本身份信息/设备信息 + "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" + } + + # 发送请求 + respond = requests.get(url = url, params = data, headers = headers) + + # 返回内容 + return respond + +def GetInfo(): + """获取视频数据""" + # 请求网址 + url = "https://api.bilibili.com/x/web-interface/wbi/search/type?category_id=&search_type=video&ad_resource=5654&__refresh__=true&_extra=&context=&page=2&page_size=42&pubtime_begin_s=0&pubtime_end_s=0&from_source=&from_spmid=333.337&platform=pc&highlight=1&single_column=0&keyword=2024%E5%B7%B4%E9%BB%8E%E5%A5%A5%E8%BF%90%E4%BC%9A&qv_id=v6jFbUhcT7bjHVQXrLt535Vt7pgQ0qf1&source_tag=3&gaia_vtoken=&dynamic_offset=24&web_location=1430654&w_rid=532d2b5246861f41eb2ab975ff882c0d&wts=1726475442" + + # 发送请求 + 获取数据 + Jsondata = GetResponse(url = url, data = None).json() + ### print("Json数据:", Jsondata) + + # 解析数据,提取视频信息 + result = Jsondata['data']['result'] + + #for 循环遍历,提取列表里面元素 + for index in result: + # 提取具体数据内容,保存字典里面 + dit = { + 'bvid': index['bvid'] + } + print(dit) + +if __name__ == '__main__': + GetInfo() \ No newline at end of file