1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| def downvideo(id,url,now): headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1' } res = requests.get(url,verify=False,headers=headers) with open(now+'/html.txt','wb') as f: f.write(res.content) new_file = open(now+'/html.txt') data = new_file.readlines() new_file.close() for line in data: if 'playAddr:' in line: playurl = re.findall(r'playAddr:(.+?)\,', line)[0] playurl = playurl.replace('playwm', 'play') playurl = playurl.replace("\"", "") postHeaders = { 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1' } locationResponse = requests.get(playurl,verify=False,headers=postHeaders,allow_redirects=False) locationUrl = locationResponse.headers['location'] videoRes = requests.get(locationUrl,headers=headers,verify=False) try: with open(now+'/video.mp4', 'wb') as f: f.write(videoRes.content) f.flush() setTaskStatus(id,'3',(now+'/video.mp4').replace('app/','')) print("下载完成!!!!") except: setTaskStatus(id, '4', '') print("下载失败!!!!")
|