前言
本文的文字及圖片來源于網路,僅供學習、交流使用,不具有任何商業用途,如有問題請及時聯系我們以作處理,
基本環境配置
- python 3.6
- pycharm
- requests
- parsel
相關模塊pip安裝即可
主要是前幾天
目標網頁
請求網頁
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)
123456
決議網頁,提取資料
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 = https://www.cnblogs.com/hhh188764/archive/2020/09/28/zip(urls, titles)
for i in data:
mp3_url = 'https:' + i[0]
title = i[1]
12345678
保存資料
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)
12345
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/134893.html
標籤:其他
