Reprinted python3 reptiles (2) have a fixed link to download the video

A few months ago I found friends there, that there was a project to work together, simply, is to download online video. It was very difficult, and ultimately did not get, presumably a loss, a recent study python, try to learn it.

Real case:

1. easily find a web video (non-streaming media), I'm here with the package diagram network, go to our homepage https://ibaotu.com/

2. Search for "New Year Video", there will be a list of videos, the first point, https://ibaotu.com/sucai/513488.html , as follows:

3. The first test is capable of playing, click the play button will be playing pop, as follows:

4. We turn off the player window, F12 packet capture and then click the play button, grab my bag, looking for playing address, as shown below, it is easy to find a video address: https://pic.ibaotu.com/00/51/34/ 88a888piCbRB.mp4

5. We use the following download this video,

import requests
 
print("开始下载")
url = 'https://pic.ibaotu.com/00/51/34/88a888piCbRB.mp4'
r = requests.get(url, stream=True)
 
with open('test.mp4', "wb") as mp4:
    for chunk in r.iter_content(chunk_size=1024 * 1024):
        if chunk:
            mp4.write(chunk)
 
print("下载结束")
 
 

6. saw the same directory successfully downloaded the video, then the browser to download this video, compare is exactly the same.

注:这个只是简单的测试,也只是7行代码,完成了不可思议的功能(相比其他语言如C++)。在实际的项目中找视频链接有点困难的,本来这个教程我想用CSDN上面的免费试看视频做样例,抓了一下包又是m3u8文件又是ts文件的,分析视频地址有点困难,还有自己一向喜欢看直播,不知道直播会有什么样的地址,又是怎么弄得,本来想花时间搞明白这个事情,想想还是算了,目前学习的核心是爬虫,下载视频先到这里,简单做个记录,爬虫学的差不多了下载视频再做详细学习。不能弄得鸡飞蛋打一个捞不着。 一个好用的python下载视频的神器 “you-get”,能直接从网页里面解析视频地址,使用教程请看: https://blog.csdn.net/zwx19921215/article/details/85249676 此处先记载下来以后再做细致研究
发布了24 篇原创文章 · 获赞 8 · 访问量 1203

Guess you like

Origin blog.csdn.net/qq_41739233/article/details/104073787