python下載mp4

 

 

 

urllib.request.urlretrieve(video_url,'./videos/%s.mp4'%(title))

 

下載多了不能用了;

  req = requests.get(url, headers=self.headers, stream=True, verify=False,timeout=500)
            with(open(target_dir + movie_name + '.mp4', 'wb')) as f:

                pbar = tqdm(total=100)
                for chunk in req.iter_content(chunk_size=10000):
                    if chunk:
                        f.write(chunk)
                        downsize += len(chunk)
                        # line = 'downloading %d KB/s - %.2f MB, 共 %.2f MB'
                        pbar.update(1)
                        # line = line % (
                        #     downsize / 1024 * 5 / (time.time() - startTime), downsize / 1024 * 5 / 1024 * 5,
                        #     downsize / 1024 * 5 / 1024 * 5)
                        # print(line)
                pbar.close()

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章