为了看动漫无职转生,找到了一个网站,进行本地存储,同样的ts文件。
1、访问网站
提示:一定要带上user-agen。
2、保存路径
3、m3u8路径
4、对每个ts文件进行请求
提示:每请求一次就存入一次,全部合成会报错。
效果图
代码整合
import re
from tqdm import tqdm
import requests
from lxml import etree
import os
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36'
}
url_l = 'http://www.ynzdhc.com/cc_play/bJDW5N-1-2.html'
res_list = requests.get(url_l,headers=headers)
r = etree.HTML(res_list.text)
name = "".join(r.xpath('//div[@class="videobase"]//text()')).strip()
outfile_name = 'D:/PyCharm 2021.2.2/viodes' + name + '.mp4'
if os.path.exists(outfile_name):
os.remove(outfile_name)
m3u8_list = ''.join(re.findall('url":"(.*?)","url_next',res_list.text)[0].split('\\'))
resq_m3u8= requests.get(m3u8_list,headers=headers)
m3u8 = m3u8_list.split('.com')[0]+'.com' +''.join(re.findall('\n(.*?).m3u8',resq_m3u8.text))+'.m3u8'
m3u8_ts =requests.get(m3u8,headers=headers)
url_date = re.findall(r'EXTINF:.*,\n(.*?)\n', m3u8_ts.text)
for url_ts in tqdm(url_date,desc=f"正在请求 {name}"):
link_content = requests.get(url_ts, headers=headers, timeout=25).content
with open(outfile_name, 'ab+') as f:
f.write(link_content)
|