基于Python爬取素材網(wǎng)站音頻文件
基本環(huán)境配置
python 3.6 pycharm requests parsel相關(guān)模塊pip安裝即可
目標(biāo)網(wǎng)頁
請(qǐ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)
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. ASP實(shí)現(xiàn)加法驗(yàn)證碼2. 無線標(biāo)記語言(WML)基礎(chǔ)之WMLScript 基礎(chǔ)第1/2頁3. ASP刪除img標(biāo)簽的style屬性只保留src的正則函數(shù)4. PHP循環(huán)與分支知識(shí)點(diǎn)梳理5. ASP基礎(chǔ)入門第三篇(ASP腳本基礎(chǔ))6. 利用CSS3新特性創(chuàng)建透明邊框三角7. 解析原生JS getComputedStyle8. css代碼優(yōu)化的12個(gè)技巧9. 前端從瀏覽器的渲染到性能優(yōu)化10. 讀大數(shù)據(jù)量的XML文件的讀取問題
