b站視頻音頻獲取簡單實踐~以Lumi美麗的神話為例
分析網(wǎng)頁源代碼 找到音視頻標(biāo)簽? 不同鏈接對應(yīng)不同清晰度
"audio":[{"id":30280, "baseurl" : ?# 此處鏈接為音頻鏈接
"video":{{"id:80","baseurl":? # 可以根據(jù)此處鏈接獲取視頻鏈接

# 此爬蟲僅使用request第三方庫
import?requests

#?定義請求標(biāo)頭,參數(shù)詳見edge檢查功能,模擬用戶行為
headers = {'authority':'',
????????????????????'accept':'',
????????????????????'accept_encoding':'',
????????????????????'accept_language':'',
????????????????????'cookie':'',
????????????????????'referer':''?,# b站存在referer反爬機(jī)制,務(wù)必加上此項
????????????????????'user-agent':'',
}

# 爬取頁面
def get_parse():
????????response=requests.get('https://www.bilibili.com/video/BV1wY4y1f7yn/??spm_id_from=333.999.0.0&vd_source=56a22aa7ae645f665df432c707fcbd88', headers=headers)
????????print(response.status_code)
????????response.encoding = response.apparent_encoding
? ?????download(video_url, audio_url)

# 下載音頻和視頻資源
def download(video_url, audio_url):
??? ????video = requests.get(video_url, headers=headers).content
??? ????audio = requests.get(audio_url, headers=headers).content
??????? with open('美麗的神話.mp4', 'wb') as f:
??????? ????f.write(video)
??????? with open('美麗的神話.mp3', 'wb') as f:
??????????? f.write(audio)

# 運(yùn)行程序
video_url =''? # 此處為頁面分析所得的baseurl:視頻鏈接
audio_url =''??# 此處為頁面分析所得的baseurl:音頻鏈接
get_parse()
# 歡迎關(guān)注露米Lumi_Offical喵!