基于Python爬取素材網(wǎng)站音頻文件
基本環(huán)境配置
python 3.6 pycharm requests parsel相關(guān)模塊pip安裝即可
目標(biāo)網(wǎng)頁
請求網(wǎng)頁
import requestsurl = ’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 parselselector = 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:pythondemo熊貓辦公素材背景音樂’ + title + ’.mp3’ with open(path, mode=’wb’) as f: f.write(response.content)
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. XML入門精解之結(jié)構(gòu)與語法2. ASP刪除img標(biāo)簽的style屬性只保留src的正則函數(shù)3. Echarts自定義圖形的方法參考4. ASP動態(tài)網(wǎng)頁制作技術(shù)經(jīng)驗(yàn)分享5. Xml簡介_動力節(jié)點(diǎn)Java學(xué)院整理6. ASP基礎(chǔ)入門第二篇(ASP基礎(chǔ)知識)7. CSS可以做的幾個令你嘆為觀止的實(shí)例分享8. ASP實(shí)現(xiàn)加法驗(yàn)證碼9. 解析原生JS getComputedStyle10. css代碼優(yōu)化的12個技巧
