1. Identify the target
InOn the Weibo page, find a short video that you want to download and find the URL of the video through the review element.
such as://f.us.sinaimg.cn/00150tbnlx07l0qjosji01040201m7z90k010.mp4?label=mp4_720p&template=1732x720.28& Expires=1528730862&ssig=nesy89zjvy&kid=unistore,video
Precede the URL with http:
2. Using the tool
Urlrrtrieve () is to download the remote file to the local disk
The third parameter, the Reporthook function report, shows that the three parameters are: the data block that has been downloaded, the size of the data block, and the size of the remote file. According to the three parameters, we can calculate the download progress.
3. Code implementation:
1 fromUrllibImportRequest2 3 #Video Address4Base_url ='http://f.us.sinaimg.cn/00150tBNlx07l0qjoSJi01040201m7z90k010.mp4?label=mp4_720p&template=1732x720.28 &expires=1528730862&ssig=nesy89zjvy&kid=unistore,video'5 6 #Download Progress7 defReport (A,B,C):8 " "9 :p Aram A: Data blocks that have already been downloadedTen :p Aram B: Size of the data block One :p Aram C: The size of the remote file A : Return: Download percentage - " " - #under progress percent theper = 100.0 * A * b/C - ifPer > 100: -per = 100 - Print('%.2f%%'%per) + - +Request.urlretrieve (Base_url,'Weibo/1.mp4', Reporthook=report)
Urlrrtrieve () example download Weibo short video