Python爬虫采集微博视频数据
作者:松鼠爱吃饼干 发布时间:2023-08-11 16:01:03
标签:Python,采集,微博,视频数据
前言
随时随地发现新鲜事!微博带你欣赏世界上每一个精彩瞬间,了解每一个幕后故事。分享你想表达的,让全世界都能听到你的心声!今天我们通过python去采集微博当中好看的视频!
没错,今天的目标是微博数据采集,爬的是那些好看的小姐姐视频
知识点
requests
pprint
开发环境
版 本:python 3.8
-编辑器:pycharm 2021.2
爬虫原理
作用:批量获取互联网数据(文本, 图片, 音频, 视频)
本质:一次次的请求与响应
案例实现
1. 导入所需模块
import requests
import 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).content
with open(f'video\\{title}.mp4', mode='wb') as f:
f.write(video_data)
print(title, "爬取成功................")
完整代码
import requests
import pprint
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()
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爬虫采集微博视频数据的详细内容,更多关于Python采集视频数据的资料请关注脚本之家其它相关文章!
来源:https://www.cnblogs.com/qshhl/p/15637804.html


猜你喜欢
- 介绍百度aip模块是用于实现百度云与用户接口,简单来说就是使用百度云所拥有的人工智能模块。模块使用pip install baidu-aip
- 作者:Tr4c3 '为了保持脚本的通用性,放弃了 and (select col_name(objec
- 1. 简介本文介绍使用sync.Once来实现单例模式,包括单例模式的定义,以及使用sync.Once实现单例模式的示例,同时也比较了其他单
- 1、方法一在使用多线程更新 MongoDB 数据时,需要注意以下几个方面:确认您的数据库驱动程序是否支持多线程。在 PyMongo 中,默认
- 一.定义表变量DECLARE @T1 table(UserID int , UserName nvarchar(50),CityName n
- 前言一些公司内部的CMS系统存在某些内容让指定的用户有权限访问,这时候可以用django自带的权限管理进行限制,比较方便。缺点:django
- RabbitMQ可以当做一个消息代理,它的核心原理非常简单:即接收和发送消息,可以把它想象成一个邮局:我们把信件放入邮箱,邮递员就会把信件投
- Selenium 封装了现成的文件上传操作。但是随着现代前端框架的发展,文件上传的方式越来越多样。而有一些文件上传的控件,要做自动化控制会更
- 在没学习开窗函数之前,我们都知道,用了分组之后,查询字段就只能是分组字段和聚合的字段,这带来了极大的不方便,有时我们查询时需要分
- 本文实例讲述了Django框架使用富文本编辑器Uedit的方法。分享给大家供大家参考,具体如下:Uedit是百度一款非常好用的富文本编辑器一
- 1、序言  上一节快速搭建Express开发系统步骤,对如何使用express-generator创建一
- 安装部分所需文件在最下方提供STEP1双击mysql-installer-web-community-8.0.18.0.msi进行按钮如果出
- 说明:关于类的这部分,我参考了《Learning Python》一书的讲解。创建类创建类的方法比较简单,如下:class Person:&n
- 超级简单实现iframe框架滚动控制,前提要会简单修改原代码。step1:插入iframe标签在你想要的位置。<iframe 
- 描述: 日志按日期、大小回滚代码:# -*- coding: utf-8 -*-import osimport logging.handle
- 如何使用pytorch加载并读取COCO数据集 环境配置基础知识:元祖、字典、数组利用PyTorch读取COCO数据集利用PyTorch读取
- 线性逻辑回归本文用代码实现怎么利用sklearn来进行线性逻辑回归的计算,下面先来看看用到的数据。这是有两行特征的数据,然后第三行是数据的标
- 本文用python写了一个会员管理系统,供大家参考,具体内容如下:"""后台管理员前台会员信息系统1.后台管理
- 以前看过几个JS代码格式的,自己也来写了一个,呵呵,优点是可以处理超长的 JS 而不会死机.........IE Only运行代码框<
- 用phpMyAdmin时在导入和导出MySQL5数据时,有一个SQL compatibility mode选项,其可选值为NONE、ANSI