您的位置:首頁技術文章
文章詳情頁

基于Python爬取素材網站音頻文件

瀏覽:3日期:2022-07-07 15:57:48

基本環境配置

python 3.6 pycharm requests parsel

相關模塊pip安裝即可

目標網頁

基于Python爬取素材網站音頻文件基于Python爬取素材網站音頻文件

請求網頁

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)

解析網頁,提取數據

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]

保存數據

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)

基于Python爬取素材網站音頻文件基于Python爬取素材網站音頻文件

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Python 編程
相關文章:
国产综合久久一区二区三区