[Python] 纯文本查看 复制代码
import requests
import os
def get_classid(pc_id):
headers = {
'Host': 'www.houdask.com',
'Connection': 'keep-alive',
'Content-Length': '0',
'Accept': 'application/json, text/plain, */*',
'Origin': 'http://www.houdask.com',
'User-Agent': 'Mozilla/5.0 (Linux; Android 10; MI 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Mobile Safari/537.36',
'Referer': 'http://www.houdask.com/site/hd/resources/views/free/play.html?id=8145&type=1',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9',
}
params = (
('data', '{"courseType":"1","videoId":%s}' % pc_id),
)
response = requests.post('http://www.houdask.com/api/other/freeclassvideo/anon/pc/video/get/details', headers=headers, params=params)
class_id = response.json()["data"]["classVideo"]["classId"]
return class_id
def spide_adress(pc_id):
name_list = []
adress_list = []
num = 0
headers = {
'Host': 'www.houdask.com',
'Connection': 'keep-alive',
'Content-Length': '36',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Origin': 'http://www.houdask.com',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Linux; Android 10; MI 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Mobile Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Referer': 'http://www.houdask.com/site/hd/resources/wap/play.html?classId=499',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9',
}
data = {
'data': '{"classId":%s}'% get_classid(pc_id)
}
response = requests.post('http://www.houdask.com/api/other/freeclassvideo/anon/wap/video/get/details/list', headers=headers, data=data)
# response.json() 获取响应的json数据 数据类型为字典
response_json = response.json()
video_list = response_json["data"]["videoList"]
tictle = response_json["data"]["phaseName"]
# print(type(response_json), type(video_list[1]["videoName"]), type(tictle))
for every_dict in video_list:
name = every_dict["videoName"]
video_adress = every_dict["video"]
name_list.append(name)
adress_list.append(video_adress)
num = num + 1
return name_list, adress_list, tictle, num
def write_file(name_list, adress_list, tictle, num):
with open(r'{}\Desktop\{}-{}.m3u'.format(os.environ.get('USERPROFILE'), tictle, name_list[num-1]), 'w', encoding='utf-8')as f:
f.write('#EXTM3U' + '\n')
for index, name in enumerate(name_list):
f.write('#EXTINF:0' + ',' + name + '\n')
f.write(adress_list[index] + '\n')
if __name__ == "__main__":
pc_id = str(input('请输入视频Id:'))
name_list, adress_list, tictle, num = spide_adress(pc_id)
write_file(name_list, adress_list, tictle, num)
print('播放列表文件创建成功')
print('===============================')
input('按任意键推出')