import requests, re, json, os
url = ""
headers = {
'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36',
'cookie' : ''
}
data = requests.get(url=url, headers=headers)
data.encoding = 'utf-8'
data = data.text
data_en = re.findall('<script id="RENDER_DATA" type="application/json">(.*?)</script></head><body >',data)[0]
data_all = requests.utils.unquote(data_en)
# 解析视频url:正则
video_url = 'https:' + re.findall('"playAddr":\[{"src":".*?{"src":"(.*?)"}]',data_all)[0]
# print(video_url)
# 正则
comments = re.findall("\"comments\":\[(.*?)],\"consumerTime\":",data_all)
# print(comments)
# title
title = re.findall('"desc":"(.*?)","authorUserId"',data_all)[0].replace(' ','')
#保存
if not os.path.exists('./video'):
os.mkdir('./video')
video_content = requests.get(url=video_url, headers=headers).content
with open(f'./video/{title}.mp4', 'wb+') as f:
f.write(video_content)