python爬取素材图片代码_基于Python爬取素材网站音频文件
基本環(huán)境配置
python 3.6
pycharm
requests
parsel
相關(guān)模塊pip安裝即可
目標(biāo)網(wǎng)頁(yè)
請(qǐng)求網(wǎng)頁(yè)
import requests
url = '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 parsel
selector = 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:\\python\\demo\\熊貓辦公素材\\背景音樂\\' + title + '.mp3'
with open(path, mode='wb') as f:
f.write(response.content)
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
總結(jié)
以上是生活随笔為你收集整理的python爬取素材图片代码_基于Python爬取素材网站音频文件的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 以人工智能奏响大数字发展号角,开启数字经
- 下一篇: 御风未来自研 eVTOL M1 飞行器获