Python视频爬虫实现下载头条视频功能示例
作者:开心果汁 时间:2021-06-30 05:43:02
本文实例讲述了Python视频爬虫实现下载头条视频功能。分享给大家供大家参考,具体如下:
一、需求分析
抓取头条短视频
思路:
分析网页源码,查找解析出视频资源url(查看源代码,搜mp4)
对该url发起请求,返回二进制数据
将二进制数据保存为视频格式
视频链接:
http://video.eastday.com/a/170612170956054127565.html
二、代码实现
# encoding: utf-8
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)
#视频是二进制数据流,content就是为了获取二进制数据的方法
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
成功下载可以播放~
希望本文所述对大家Python程序设计有所帮助。
来源:https://blog.csdn.net/u013421629/article/details/73134804
标签:Python,视频爬虫
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
SQL Server 2008数据挖掘查询任务
2009-03-16 16:50:00
Python Web编程之WSGI协议简介
2022-08-30 10:39:03
python开发之IDEL(Python GUI)的使用方法图文详解
2023-09-15 23:22:42
![](https://img.aspxhome.com/file/2023/8/62568_0s.png)
javascript下兼容firefox选取textarea文本的代码
2013-08-30 02:05:16
用PyInstaller把Python代码打包成单个独立的exe可执行文件
2022-12-02 09:15:11
![](https://img.aspxhome.com/file/2023/9/120269_0s.png)
用Python复现二战德军enigma密码机
2022-04-12 23:22:59
![](https://img.aspxhome.com/file/2023/1/76191_0s.png)
纯手工打造CSS像素画
2009-03-09 12:57:00
![](https://img.aspxhome.com/file/UploadPic/20093/9/01-12s.gif)
实现文字放大效果Javascript源码
2010-03-17 20:46:00
![](https://img.aspxhome.com/file/UploadPic/20103/17/2010317204821421s.jpg)
从语义开始–概念、意义、实践
2010-06-13 18:06:00
![](https://img.aspxhome.com/file/UploadPic/20106/13/01-73s.jpg)
多个版本的python共存时使用pip的正确做法
2021-06-24 10:41:17
Python实现强制复制粘贴的示例详解
2021-03-30 23:58:43
![](https://img.aspxhome.com/file/2023/6/69036_0s.png)
python中的路径拼接问题
2021-02-06 11:28:56
![](https://img.aspxhome.com/file/2023/9/101639_0s.png)
WPF自定义搜索框代码分享
2023-07-18 23:31:04
![](https://img.aspxhome.com/file/2023/1/79061_0s.jpg)
Python接收Gmail新邮件并发送到gtalk的方法
2022-03-05 22:39:01
python通过urllib2获取带有中文参数url内容的方法
2022-07-26 10:35:58
修正IE6不支持position:fixed的bug[译]
2009-08-01 12:44:00
js实现屏蔽默认快捷键调用自定义事件示例
2023-09-05 09:28:31
python修改字典键(key)的方法
2023-04-16 20:26:57
![](https://img.aspxhome.com/file/2023/3/107663_0s.jpg)
python 边缘扩充方式的实现示例
2021-03-30 23:28:17
![](https://img.aspxhome.com/file/2023/4/115514_0s.jpg)
Python socket实现的文件下载器功能示例
2021-03-12 22:43:19