In the python has been linked video download

  When using python crawling video site, you will be a series of video links, such as MP4 files. Need to get the video after downloading the video file, you write a function to download video files. In which a list of all the video files video_links before crawling to the links. Saved video file named file name of the video links. Use link.split ( '/') will be segmented links, to get a list, select the video file name is the last element of the list with an extension.

import requests

def
download_videofile(video_links): root='保存文件位置' for link in video_links: file_name = link.split('/')[-1] print("Downloading file:%s" % file_name) r = requests.get(link, stream=True) with open(root+file_name, 'wb') as f: for chunk in r.iter_content(chunk_size=1024 * 1024): if chunk: f.write(chunk) print("%s downloaded!\n" % file_name) print("All videos downloaded!") return if __name__ == "__main__": video_links=[视频链接1] download_video_series(video_links)

FIG operating results as follows:

 

Guess you like

Origin www.cnblogs.com/qing0228/p/11184553.html