基于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. 利用promise及參數(shù)解構(gòu)封裝ajax請求的方法2. asp(vbs)Rs.Open和Conn.Execute的詳解和區(qū)別及&H0001的說明3. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向4. .NET中l(wèi)ambda表達(dá)式合并問題及解決方法5. PHP設(shè)計(jì)模式中工廠模式深入詳解6. JSP數(shù)據(jù)交互實(shí)現(xiàn)過程解析7. windows服務(wù)器使用IIS時(shí)thinkphp搜索中文無效問題8. ThinkPHP5實(shí)現(xiàn)JWT Token認(rèn)證的過程(親測可用)9. 如何基于Python Matplotlib實(shí)現(xiàn)網(wǎng)格動畫10. Ajax實(shí)現(xiàn)表格中信息不刷新頁面進(jìn)行更新數(shù)據(jù)
