https://www.52pojie.cn/thread-1032509-1-1.html
以上文章给出的代码稍有点问题,可有是某讯把里返回结果改了一下吧,造成获取的数据内容不对了,也许是本来不同的视频返回结果是不一样的,我是为了获得“3月23日《如何培养孩子的学习习惯与学习方法》专题教育”的视频,而改的如下代码,可以正常获得对应的URL。
import requests
import json
import re
headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0'}
def qq_video(url):
appver = '3.2.19.333'
try:
vid = url.split('/')[-1].split('.')[0]
except:
vid = url
print("vid:" + vid)
url = 'http://vv.video.qq.com/getinfo?otype=json&platform=11&defnpayver=1&appver=' + appver + '&defn=fhd&vid=' + vid
html = requests.get(url, headers=headers)
html_text = html.text
print("html.text:" + html.text)
jsonstr = re.findall('QZOutputJson=(.+);$', html_text, re.S)[0]
print("jsonstr:" + jsonstr)
json_data = json.loads(jsonstr)
fvkey = json_data['vl']['vi'][0]['fvkey']
print("fvkey:" + fvkey)
# keyid = json_data['vl']['vi'][0]['cl']['keyid'].split(".")
# print("keyid:"+keyid)
# filename = keyid[0] + ".p" + keyid[1][2:] + "." + keyid[2] + ".mp4"
filename = json_data['vl']['vi'][0]['fn']
print("filename:" + filename)
cdn = json_data['vl']['vi'][0]['ul']['ui'][3]['url']
print("cdn:" + cdn)
downloadurl = cdn + filename + "?vkey=" + fvkey + "?type=mp4"
print("DownloadUrl:" + downloadurl)
## path = "E:\\Temp\\"+filename
## r = requests.get(url)
## print("ok")
## with open(path, "wb") as f:
## f.write(r.content)
## f.close()
if __name__ == "__main__":
# url = input("Put:")
url = "https://v.qq.com/x/page/a08530zb1c5.html"
qq_video(url)