#导入模块
import json
import re
import requests
import pprint
import time
#发送请求
url = input("请输入一个链接: ")
# url = "https://www.acfun.cn/v/ac32884784"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0."
}
response = requests.get(url=url,headers=headers)
# print(response.text)
html_data= re.findall('window.pageInfo = window.videoInfo = (.*?);',response.text)[0]
json_data= json.loads(html_data)
# print(html_data)
# pprint.pprint(json_data)
title = json_data['title']
video_info= json_data['currentVideoInfo']['ksPlayJson']
video_json= json.loads(video_info)['adaptationSet'][0]['representation'][0]['backupUrl'][0] #m3u8
pprint.pprint((video_json))
print(title)
m3u8_data= requests.get(url=video_json,headers=headers).text
m3u8_data= re.sub('#E.*','',m3u8_data).split()
# print(m3u8_data)
for index in m3u8_data:
ts_url='https://ali-safety-video.acfun.cn/mediacloud/acfun/acfun_video/'+ index
ts_name= index.split('.')[1]
# print(ts_url)
# print(ts_name)
ts_content= requests.get(url=ts_url,headers=headers).content
with open('video\\'+ title+'.mp4',mode='ab') as f:
f.write(ts_content )
print(ts_name )
input("Press Enter to exit...")
====================================================================
注意需要在代码文件夹下提前创建video文件夹
输入视频链接后即可下载
|´・ω・)ノヾ(≧∇≦*)ゝ(☆ω☆)(╯‵□′)╯︵┴─┴ ̄﹃ ̄(/ω\)∠( ᐛ 」∠)_(๑•̀ㅁ•́ฅ)→_→୧(๑•̀⌄•́๑)૭٩(ˊᗜˋ*)و(ノ°ο°)ノ(´இ皿இ`)⌇●﹏●⌇(ฅ´ω`ฅ)(╯°A°)╯︵○○○φ( ̄∇ ̄o)ヾ(´・ ・`。)ノ( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃(ó﹏ò。)Σ(っ °Д °;)っ( ,,´・ω・)ノ╮(╯▽╰)╭ o(*////▽////*)q >﹏<( ๑´•ω•) (。•ˇ‸ˇ•。)
|´・ω・)ノヾ(≧∇≦*)ゝ(☆ω☆)(╯‵□′)╯︵┴─┴ ̄﹃ ̄(/ω\)∠( ᐛ 」∠)_(๑•̀ㅁ•́ฅ)→_→୧(๑•̀⌄•́๑)૭٩(ˊᗜˋ*)و(ノ°ο°)ノ(´இ皿இ`)⌇●﹏●⌇(ฅ´ω`ฅ)(╯°A°)╯︵○○○φ( ̄∇ ̄o)ヾ(´・ ・`。)ノ( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃(ó﹏ò。)Σ(っ °Д °;)っ( ,,´・ω・)ノ╮(╯▽╰)╭ o(*////▽////*)q >﹏<( ๑´•ω•) (。•ˇ‸ˇ•。)
|´・ω・)ノヾ(≧∇≦*)ゝ(☆ω☆)(╯‵□′)╯︵┴─┴ ̄﹃ ̄(/ω\)∠( ᐛ 」∠)_(๑•̀ㅁ•́ฅ)→_→୧(๑•̀⌄•́๑)૭٩(ˊᗜˋ*)و(ノ°ο°)ノ(´இ皿இ`)⌇●﹏●⌇(ฅ´ω`ฅ)(╯°A°)╯︵○○○φ( ̄∇ ̄o)ヾ(´・ ・`。)ノ( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃(ó﹏ò。)Σ(っ °Д °;)っ( ,,´・ω・)ノ╮(╯▽╰)╭ o(*////▽////*)q >﹏<( ๑´•ω•) (。•ˇ‸ˇ•。)
|´・ω・)ノヾ(≧∇≦*)ゝ(☆ω☆)(╯‵□′)╯︵┴─┴ ̄﹃ ̄(/ω\)∠( ᐛ 」∠)_(๑•̀ㅁ•́ฅ)→_→୧(๑•̀⌄•́๑)૭٩(ˊᗜˋ*)و(ノ°ο°)ノ(´இ皿இ`)⌇●﹏●⌇(ฅ´ω`ฅ)(╯°A°)╯︵○○○φ( ̄∇ ̄o)ヾ(´・ ・`。)ノ( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃(ó﹏ò。)Σ(っ °Д °;)っ( ,,´・ω・)ノ╮(╯▽╰)╭ o(*////▽////*)q >﹏<( ๑´•ω•) (。•ˇ‸ˇ•。)