Python爬虫如何采集微博视频数据
发表于:2025-11-20 作者:千家信息网编辑
千家信息网最后更新 2025年11月20日,这篇文章主要介绍了Python爬虫如何采集微博视频数据,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。知识点requestspprint
千家信息网最后更新 2025年11月20日Python爬虫如何采集微博视频数据
这篇文章主要介绍了Python爬虫如何采集微博视频数据,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
知识点
requests
pprint
开发环境
版 本:python 3.8
-编辑器:pycharm 2021.2
爬虫原理
作用:批量获取互联网数据(文本, 图片, 音频, 视频)
本质:一次次的请求与响应

案例实现
1. 导入所需模块
import requestsimport pprint
2. 找到目标网址
打开开发者工具,选中Fetch/XHR,选中数据所在的标签,找到目标所在url
https://www.weibo.com/tv/api/component?page=/tv/channel/4379160563414111/editor
3. 发送网络请求
headers = { 'cookie': '', 'referer': 'https://weibo.com/tv/channel/4379160563414111/editor', 'user-agent': '',}data = { 'data': '{"Component_Channel_Editor":{"cid":"4379160563414111","count":9}}'}url = 'https://www.weibo.com/tv/api/component?page=/tv/channel/4379160563414111/editor'json_data = requests.post(url=url, headers=headers, data=data).json()4. 获取数据
json_data_2 = requests.post(url=url_1, headers=headers, data=data_1).json()
5. 筛选数据
dict_urls = json_data_2['data']['Component_Play_Playinfo']['urls']video_url = "https:" + dict_urls[list(dict_urls.keys())[0]]print(title + "\t" + video_url)
6. 保存数据
video_data = requests.get(video_url).contentwith open(f'video\\{title}.mp4', mode='wb') as f: f.write(video_data)print(title, "爬取成功................")
完整代码
import requestsimport pprintheaders = { 'cookie': '添加自己的', 'referer': 'https://weibo.com/tv/channel/4379160563414111/editor', 'user-agent': '',}data = { 'data': '{"Component_Channel_Editor":{"cid":"4379160563414111","count":9}}'}url = 'https://www.weibo.com/tv/api/component?page=/tv/channel/4379160563414111/editor'json_data = requests.post(url=url, headers=headers, data=data).json()print(json_data)ccs_list = json_data['data']['Component_Channel_Editor']['list']next_cursor = json_data['data']['Component_Channel_Editor']['next_cursor']for ccs in ccs_list: oid = ccs['oid'] title = ccs['title'] data_1 = { 'data': '{"Component_Play_Playinfo":{"oid":"' + oid + '"}}' } url_1 = 'https://weibo.com/tv/api/component?page=/tv/show/' + oid json_data_2 = requests.post(url=url_1, headers=headers, data=data_1).json() dict_urls = json_data_2['data']['Component_Play_Playinfo']['urls'] video_url = "https:" + dict_urls[list(dict_urls.keys())[0]] print(title + "\t" + video_url) video_data = requests.get(video_url).content with open(f'video\\{title}.mp4', mode='wb') as f: f.write(video_data) print(title, "爬取成功................")感谢你能够认真阅读完这篇文章,希望小编分享的"Python爬虫如何采集微博视频数据"这篇文章对大家有帮助,同时也希望大家多多支持,关注行业资讯频道,更多相关知识等着你来学习!
数据
篇文章
爬虫
视频
成功
所在
目标
知识
开发
互联网
代码
价值
作用
兴趣
原理
同时
图片
工具
开发者
文本
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
幻塔第一服务器是哪个
网络安全上市企业盈利
软件工程数据库导论1000字
三级网络技术学习资料
计算机网络技术包含cad吗
学软件开发编程语言
中创科达软件开发
二手服务器转让
e网服务器在萨尔瓦多
流行的软件开发项目
素描青少年网络安全课堂
软件开发者与商城合作协议
数据库导出图标
南京环保软件开发节能规范
科技创新中互联网的作用
2021年网络安全班会图片
手机热点输入网络安全密钥
qt中数据库精确查询
数据库 入口
魔兽世界各服务器配置要求
exac基因数据库
数据库在列上创建
数据库去掉数前的0
数据库中truncate
软件开发基准数据
中介服务超市软件开发
数据库导出图标
为什么有那么多数据库
数据库如何挖关联规则
昆山同日自动化软件开发