本帖最后由 Cellluo 于 2020-5-15 21:06 编辑
def download(url, root_path):
# ts_url = ts_urls[i]
file_name = url.split("/")[-1]
print("开始下载 %s" % file_name)
start = datetime.datetime.now().replace(microsecond=0)
try:
response = requests.get(url, stream=True, verify=False)
except Exception as e:
print("异常请求:%s" % e.args)
return
with open(file_name, "wb+") as file:
for chunk in response.iter_content(chunk_size=1024):
if chunk:
file.write(chunk)
end = datetime.datetime.now().replace(microsecond=0)
print("耗时:%s" % (end-start))
for index, m3u8_url in enumerate(all_urls):
print(m3u8_url)
file_name = '/Users/nianfouyi/Desktop/test/'+str(index)+'.ts'
download(m3u8_url, file_name)
time.sleep(5)
print("OK")
单独调用这个函数下载m3u8视频的每个.ts视频,下载下来就是正常的,如果用for 循环的话,每个.ts只有166字节,下载不正常,求大佬指教[/md] |