# https://tx-safety-video.acfun.cn/mediacloud/acfun/acfun_video/d1b7a414393175ae-e2f26d4bac178e3f6d33e56ed8e12366-hls_1080p_h264_6m_1.m3u8
import json
import os
import requests
import re
from pprint import pprint
url='https://www.acfun.cn/v/ac41909431'
url_left='https://tx-safety-video.acfun.cn/mediacloud/acfun/acfun_video/'
page=0
headers={
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'
}
response=requests.get(url,headers=headers,timeout=5 )
# print(response.text)
title=re.findall('"title":"(.*?)",',response.text)[1]
# title1=re.findall('"fileName":"(.*?)",',response.text)
print(title)
# main_body=re.findall('window.pageInfo = window.videoInfo =(.*?)',response.text)[0]
html_data=re.findall('window.pageInfo = window.videoInfo = (.*);',response.text)[0]
# print(response.text)
# print(type(html_data))
# print(newbee)
json_data=json.loads(html_data)
# pprint(json_data)
# print(type(json_data))
json_data1=json_data['currentVideoInfo']['ksPlayJson']
m3u8_url=json.loads(json_data1)['adaptationSet'][0]['representation'][0]['url']
# print(type(json_data2),len(json_data2))
# print(m3u8_url)
url_resp=requests.get(url=m3u8_url,headers=headers).text
# print(url_resp)
ts_info_list=re.sub('#.*','',url_resp).split()
glab=0
# exit()
for ts_info in ts_info_list:
""" glab=glab+1
if glab>3:
exit()
"""
# print(ts_info)
complete=url_left+ts_info
# print(complete)
content= requests.get(complete,headers=headers).content
with open('video\\'+ f'{title}.mp4','ab') as f:
page+=1
f.write(content)
跟着b站视屏爬acfun视屏(m3u8)
最新推荐文章于 2024-08-26 18:56:03 发布