前言
本文的文字及圖片來源于網路,僅供學習、交流使用,不具有任何商業用途,著作權歸原作者所有,如有問題請及時聯系我們以作處理,
專案目標
爬取音效素材
受害者地址
http://sc.chinaz.com/yinxiao/
爬蟲代碼
匯入工具
import requests import parsel
請求網站
url = 'http://sc.chinaz.com/yinxiao/index_{}.html'.format(page) 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)
決議網站資料,爬取資料
selector = parsel.Selector(response.text) urls = selector.css('#musiclist .n1::attr(thumb)').getall() titles = selector.css('#musiclist .z a::attr(alt)').getall() data = zip(urls, titles) for i in data: print(i) download_url = i[0] title = i[1] response_2 = requests.get(url=download_url, headers=headers)
保存資料
filename = 'C:\\Users\\Administrator\\Desktop\\新建檔案夾\\' + title + '.mp3' with open(filename, mode='wb') as f: f.write(response_2.content)
運行代碼,效果如下圖
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/162321.html
標籤:Python
上一篇:python生成亂數:uniform(), randint(), gauss(), expovariate()
下一篇:Python pymysql
