1 import requests 2 from multiprocessing import Pool 3 4 5 def temp1(n): 6 # for i in range(n): 7 # url = "https://youku.cdn-tudou.com/20180515/5909_07808cae/1000k/hls/f4a95697adb%03d.ts" 8 url = "https://vip.okokbo.com/20171230/WGIUsKmD/800kb/hls/zltS5RQ81631%03d.ts" % n 9 headers = { 10 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 11 } 12 print(url) 13 r = requests.get(url, headers=headers) 14 f = open(\'./mp4/{}\'.format(url[-10:]), \'ab\') 15 f.write(r.content) 16 f.close() 17 18 19 if __name__ == \'__main__\': 20 21 pool = Pool(20) 22 for i in range(1500): 23 pool.apply_async(temp1, (i,)) 24 25 pool.close() 26 pool.join() 27 28 # copy /b *.ts new.mp4
1 import requests 2 from multiprocessing import Pool 3 4 a=input("请输入不变的地址部分:") 5 processNumber = eval(input("请输入进程总数:")) 6 7 def temp1(n): 8 # for i in range(n): 9 10 url = (a + "%03d.ts") % n 11 headers = { 12 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" 13 } 14 print(url) 15 r = requests.get(url, headers=headers) 16 f = open(\'./mp4/{}\'.format(url[-10:]), \'ab\') 17 f.write(r.content) 18 f.close() 19 20 21 if __name__ == \'__main__\': 22 23 pool = Pool(20) 24 for i in range(processNumber): 25 pool.apply_async(temp1, (i,)) 26 27 pool.close() 28 pool.join() 29 print("下载完成!,cmd合成命令:copy/b *.ts [名字].mp4") 30 # copy /b *.ts new.mp4