Python Reptile download video files section Source

 

 

Share the code myself finishing, two parameters can be changed using (next Fanger Wei code scanning to obtain python learning materials)

Import Requests
 Import Time         
headers = {
     ' the User-- Agent ' : ' the Mozilla / 5.0 (the Windows NT 10.0; Win64; x64-) AppleWebKit / 537.36 (KHTML, like the Gecko) the Chrome / 80.0.3987.132 Safari / 537.36 ' 
} 
movie_url = ' here address input video, for example: HTTP: //www.***********.mp4 ' 
MOVIE_NAME = ' video title ' 
DOWNSIZE = 0
 Print ( ' begin download ' ) 
the startTime = the time.time () 
REQ= requests.get(movie_url, headers=headers, stream=True, verify=False)  
      with(open(movie_name+'.mp4', 'wb')) as f:
          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'
                  line = line % (
                    downsize / 1024 / (time.time() - startTime), downsize / 1024 / 1024, downsize / 1024 / 1024)
                  print(line)

 

Guess you like

Origin www.cnblogs.com/0pen1/p/12431733.html