基于Python實(shí)現(xiàn)下載網(wǎng)易音樂(lè)代碼實(shí)例
代碼如下
# 爬取網(wǎng)易音樂(lè)import requestsfrom bs4 import BeautifulSoupimport urllib.requestheaders = {'origin': 'https://music.163.com', 'referer': 'https://music.163.com/', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'}url = 'http://music.163.com/playlist?id=2182968685'response = requests.get(url, headers=headers).contentresp = BeautifulSoup(response, 'lxml')mains = resp.find('ul', {'class': 'f-hide'})lists = []for music in mains.find_all('a'): list = [] # 拼裝下載地址 musicUrl = ’http://music.163.com/song/media/outer/url’ + music[’href’][5:] + ’.mp3’ musicname = music.text list.append(musicUrl) list.append(musicname) lists.append(list)for i in lists: url = i[0] name = i[1] try: print('正在下載:{}'.format(name)) urllib.request.urlretrieve(url, 'D:腳本項(xiàng)目lianxiMP3%s.mp3'%name) except: print('下載失敗')
結(jié)果展示
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 不使用XMLHttpRequest對(duì)象實(shí)現(xiàn)Ajax效果的方法小結(jié)2. 用xslt將xml解析成xhtml的代碼3. Ajax實(shí)現(xiàn)省市縣三級(jí)聯(lián)動(dòng)4. Ajax原理與應(yīng)用案例快速入門教程5. ASP.NET MVC使用Log4Net記錄異常日志并跳轉(zhuǎn)到靜態(tài)頁(yè)6. PHP設(shè)計(jì)模式中的命令模式7. PHP設(shè)計(jì)模式中觀察者模式講解8. Python Pandas常用函數(shù)方法總結(jié)9. .NET 6 跨服務(wù)器聯(lián)表查詢操作MySql、Oracle、SqlServer等相互聯(lián)表10. 詳解JS前端使用迭代器和生成器原理及示例
