本文摘自php中文网,作者不言,侵删。
这篇文章主要介绍了Python视频爬虫实现下载头条视频功能,涉及Python正则匹配、网络传输及文件读写等相关操作技巧,需要的朋友可以参考下本文实例讲述了Python视频爬虫实现下载头条视频功能。分享给大家供大家参考,具体如下:
一、需求分析
抓取头条短视频
思路:
分析网页源码,查找解析出视频资源url(查看源代码,搜mp4)
对该url发起请求,返回二进制数据
将二进制数据保存为视频格式
视频链接:
http://video.eastday.com/a/170612170956054127565.html
二、代码实现
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | import sys
reload (sys)
sys.setdefaultencoding( 'utf-8' )
import requests
import re
import time
time1 = time.time()
main_url = 'http://video.eastday.com/a/170612170956054127565.html'
resp = requests.get(main_url)
resp.encoding = 'utf-8'
html = resp.text
link = re.findall(r 'var mp4 = "(.*?)";' , html)[ 0 ]
link = 'http:' + link
dest_resp = requests.get(link)
data = dest_resp.content
path = u 'C:/赵丽颖.mp4'
f = open (path, 'wb' )
f.write(data)
f.close()
time2 = time.time()
print u 'ok,下载完成!'
print u '总共耗时:' + str (time2 - time1) + 's
|
"D:\Program Files\Python27\python.exe" D:/PycharmProjects/learn2017/testwechat.py
ok,下载完成!
总共耗时:3.20499992371s
Process finished with exit code 0
成功下载可以播放~

相关推荐:
videocapture库制作python视频高速传输程序
以上就是Python视频爬虫实现下载头条视频的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
如何用Python控制浏览器
Python各种图像库的图像读写方式的简单介绍(附代码)
Python源代码被解释器转换后的格式为什么
Python怎么转化为字符串
使用Python如何对日志进行处理 (代码)
史上最高效的Python爬虫框架(推荐)
Python swapcase函数有什么用
Python如何验证中心极限定理
Python面向对象中高级-异常处理
关于Python闭包机制的深入理解
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » Python视频爬虫实现下载头条视频