Python爬蟲采集微博視頻數(shù)據(jù)
前言
隨時(shí)隨地發(fā)現(xiàn)新鮮事!微博帶你欣賞世界上每一個(gè)精彩瞬間,了解每一個(gè)幕后故事。分享你想表達(dá)的,讓全世界都能聽到你的心聲!今天我們通過python去采集微博當(dāng)中好看的視頻!
沒錯(cuò),今天的目標(biāo)是微博數(shù)據(jù)采集,爬的是那些好看的小姐姐視頻

知識(shí)點(diǎn)
requests
pprint
開發(fā)環(huán)境
版 本:python 3.8
-編輯器:pycharm 2021.2
爬蟲原理
作用:批量獲取互聯(lián)網(wǎng)數(shù)據(jù)(文本, 圖片, 音頻, 視頻)
本質(zhì):一次次的請(qǐng)求與響應(yīng)

?案例實(shí)現(xiàn)
1. 導(dǎo)入所需模塊
import requests import pprint
2. 找到目標(biāo)網(wǎng)址
打開開發(fā)者工具,選中Fetch/XHR,選中數(shù)據(jù)所在的標(biāo)簽,找到目標(biāo)所在url


https://www.weibo.com/tv/api/component?page=/tv/channel/4379160563414111/editor
3. 發(fā)送網(wǎng)絡(luò)請(qǐng)求
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. 獲取數(shù)據(jù)
json_data_2 = requests.post(url=url_1, headers=headers, data=data_1).json()
5. 篩選數(shù)據(jù)
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. 保存數(shù)據(jù)
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爬蟲采集微博視頻數(shù)據(jù)的詳細(xì)內(nèi)容,更多關(guān)于Python采集視頻數(shù)據(jù)的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
- Python爬蟲實(shí)現(xiàn)熱門電影信息采集
- Python爬蟲實(shí)戰(zhàn)演練之采集拉鉤網(wǎng)招聘信息數(shù)據(jù)
- Python爬蟲實(shí)戰(zhàn)演練之采集糗事百科段子數(shù)據(jù)
- Python爬蟲入門案例之回車桌面壁紙網(wǎng)美女圖片采集
- 基于Python爬蟲采集天氣網(wǎng)實(shí)時(shí)信息
- Python爬蟲_城市公交、地鐵站點(diǎn)和線路數(shù)據(jù)采集實(shí)例
- 講解Python的Scrapy爬蟲框架使用代理進(jìn)行采集的方法
- Python制作爬蟲采集小說
- 詳解Python如何批量采集京東商品數(shù)據(jù)流程
相關(guān)文章
Python利用pyreadline模塊實(shí)現(xiàn)交互式命令行開發(fā)
交互式命令行是一種方便用戶進(jìn)行交互的工具,能夠使用戶與計(jì)算機(jī)進(jìn)行快速的交互操作,提高工作效率。本文主要介紹了如何利用pyreadline模塊實(shí)現(xiàn)交互式命令行開發(fā),需要的可以參考一下2023-05-05
windows下python使用ffmpeg實(shí)現(xiàn)rtsp推流
這篇文章主要為大家詳細(xì)介紹了在windows環(huán)境下python如何使用ffmpeg實(shí)現(xiàn)rtsp推流,文中的示例代碼講解詳細(xì),有需要的小伙伴可以了解一下2023-09-09
使用jupyter Nodebook查看函數(shù)或方法的參數(shù)以及使用情況
這篇文章主要介紹了使用jupyter Nodebook查看函數(shù)或方法的參數(shù)以及使用情況,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-04-04
用Python中的字典來處理索引統(tǒng)計(jì)的方法
這篇文章主要介紹了用Python中的字典來處理索引統(tǒng)計(jì)的方法,字典的使用是Python學(xué)習(xí)當(dāng)中的基礎(chǔ)知識(shí),本文則是相關(guān)的一個(gè)小實(shí)踐,需要的朋友可以參考下2015-05-05
使用Python中的cookielib模擬登錄網(wǎng)站
這篇文章主要介紹了使用Python中的cookielib模擬登錄網(wǎng)站,用作生成cookie然后登錄,需要的朋友可以參考下2015-04-04

