Python-爬虫抓取视频

没什么可写的了

写点东西审核就不通过

来吧

直接看代码吧

准备:

首先确定视频地址:

"http://video.dispatch.tc.qq.com/uwMROfz2r5zEIaQXGdGlX2dfJ6lgHJ4AOe6UhfWwqaorElWS/b3061yp5y1d.p701.1.mp4?vkey=CAA8CE5008F7EFE57C6375F331B807CEBF1553D84985C11866DD4C39D1A602BBE6F2EA3E1FB6163A672D7EA924966827C5BE25A64A2E199C2A5B790A9F25F35B5D220BC9F1F8432EBA3404E705F8586A11DDB3EF9C69970B51260CFF56A1866C4AD5C3887741E3AF7C920D52943E4BD3451D79FA0047CB9A?type=mp4"

然后开始编写代码,代码较为简单,看到便可理解:

# -*-encoding:utf8 -*-import requestsimport timevideos = ["http://video.dispatch.tc.qq.com/uwMROfz2r5zEIaQXGdGlX2dfJ6lgHJ4AOe6UhfWwqaorElWS/b3061yp5y1d.p701.1.mp4?vkey=CAA8CE5008F7EFE57C6375F331B807CEBF1553D84985C11866DD4C39D1A602BBE6F2EA3E1FB6163A672D7EA924966827C5BE25A64A2E199C2A5B790A9F25F35B5D220BC9F1F8432EBA3404E705F8586A11DDB3EF9C69970B51260CFF56A1866C4AD5C3887741E3AF7C920D52943E4BD3451D79FA0047CB9A?type=mp4"]def download_mp4(video_link):    # 确定视频保存地址    path='C:/Users/zorrolzhang/Desktop//'    # 按照时间戳组装视频名    file_name = video_link.split('/')[-1][:5] + str(int(time.time()))    print("开始下载: %s" % file_name)    # 组装全 文件名    end_path_file = path + file_name + ".mp4"    r = requests.get(video_link, stream=True)    with open(end_path_file, 'wb') as f:        for chunk in r.iter_content(chunk_size=1024 * 1024):            if chunk:                f.write(chunk)        f.close()    print("下载(%s)完成!\n" % file_name)def main() :    video_link = videos[0]    download_mp4(video_link)main()

​运行截图:

 最后,欢迎关注我的公众号【头发头发等等我】

你可能感兴趣的:(随笔,脚本语言,python)