基于Python爬取素材網(wǎng)站音頻文件
更新時間:2020年10月21日 08:35:45 作者:六月流火
這篇文章主要介紹了基于Python爬取素材網(wǎng)站音頻文件,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
基本環(huán)境配置
- python 3.6
- pycharm
- requests
- parsel
相關(guān)模塊pip安裝即可
目標(biāo)網(wǎng)頁


請求網(wǎng)頁
import requests
url = 'https://www.tukuppt.com/peiyue/zonghe_0_0_0_0_0_0_1.html'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36',
}
response = requests.get(url=url, headers=headers)
解析網(wǎng)頁,提取數(shù)據(jù)
import parsel
selector = parsel.Selector(response.text)
urls = selector.css('#audio850995 source::attr(src)').getall()
titles = selector.css('.b-box .info .title::text').getall()
data = zip(urls, titles)
for i in data:
mp3_url = 'https:' + i[0]
title = i[1]
保存數(shù)據(jù)
def download(url, title):
response = requests.get(url=url, headers=headers)
path = 'D:\\python\\demo\\熊貓辦公素材\\背景音樂\\' + title + '.mp3'
with open(path, mode='wb') as f:
f.write(response.content)


以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Python?Bleach保障網(wǎng)絡(luò)安全防止網(wǎng)站受到XSS(跨站腳本)攻擊
Bleach?不僅可以清理?HTML?文檔,還能夠?qū)︽溄舆M(jìn)行處理,檢查是否是合法格式,并可以使用白名單來控制哪些?HTML?標(biāo)簽、屬性是安全的,因此非常適合用于清潔用戶輸入的數(shù)據(jù),確保網(wǎng)站安全2024-01-01
python中split(),?os.path.split()和os.path.splitext()的用法
本文主要介紹了python中split(),?os.path.split()和os.path.splitext()的用法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02
如何將matlab數(shù)據(jù)導(dǎo)入到Python中使用
這篇文章主要介紹了如何將matlab數(shù)據(jù)導(dǎo)入到Python中使用,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-12-12
Pytorch實現(xiàn)Fashion-mnist分類任務(wù)全過程
這篇文章主要介紹了Pytorch實現(xiàn)Fashion-mnist分類任務(wù)全過程,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-12-12

