import requests
import re
import os
from lxml import etree
url = “https://xunaizhan.com/xgplay/tiandichuanqi-1-1/”
h = {‘user-agent’:‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0’
}
r1 = requests.get(url=url, headers=h)
d = re.findall(r’\/(.*?.\)',r1.text)[4]
pattern = re.compile(r"[/\?“<>|]”) # ‘/ \ : * ? " < > |’
d = re.sub(pattern, “”, d) # 替换为下划线
#https://vip.lz-cdn16.com/20230323/14124_6a61dba8/2000k/hls/mixed.m3u8
m = f’https://vip.lz-cdn16.com/20230323/{d}/2000k/hls/mixed.m3u8’
r2 = requests.get(url=m, headers=h)
if not os.path.exists(“ts”):
os.mkdir(“ts”)
num = 0
data = re.findall(r’,\n(.*?.ts)', r2.text, re.S)
#https://vip.lz-cdn16.com/20230323/14124_6a61dba8/2000k/hls/a95464ecb88000001.ts
for ts in data:
#print(ts)
ts = f'https://vip.lz-cdn16.com/20230323/{d}/2000k/hls/' + ts
# print(ts)
res3 = requests.get(ts, headers=h)
with open(f'ts/{num}.ts', 'wb') as f:
f.write(res3.content)
print(f"{num}.ts文件保存完成!")
num += 1