基于Python爬取素材網(wǎng)站音頻文件
基本環(huán)境配置
python 3.6 pycharm requests parsel相關(guān)模塊pip安裝即可
目標(biāo)網(wǎng)頁(yè)
請(qǐng)求網(wǎng)頁(yè)
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)頁(yè),提取數(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熊貓辦公素材背景音樂(lè)’ + title + ’.mp3’ with open(path, mode=’wb’) as f: f.write(response.content)
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 父div高度不能自適應(yīng)子div高度的解決方案2. 淺談XML Schema中的elementFormDefault屬性3. CSS3實(shí)例分享之多重背景的實(shí)現(xiàn)(Multiple backgrounds)4. ASP中SELECT下拉菜單同時(shí)獲取VALUE和TEXT值的實(shí)現(xiàn)代碼5. servlet+jsp實(shí)現(xiàn)過(guò)濾器 防止用戶(hù)未登錄訪問(wèn)6. ASP錯(cuò)誤捕獲的幾種常規(guī)處理方式7. 利用XMLSerializer將對(duì)象串行化到XML8. 選擇模式 - XSL教程 - 29. JSP狀態(tài)管理的簡(jiǎn)單介紹10. 前端從瀏覽器的渲染到性能優(yōu)化
