爬虫网易云音乐
本帖最后由 青出于蓝 于 2022-7-28 14:21 编辑import requests
from lxml import etree
url ='https://music.163.com/discover/toplist?id=3778678'
headers = {'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'}
response = requests.get(url,headers=headers).text
#print(response)
data=etree.HTML(response)
music_list=data.xpath('//a')
#print(music_list)
for music in music_list:
href=music.xpath('./@href')
#print(href)
music_id=href.split('=')
music_name=music.xpath('./text()')
#print(music_name)
#print(music_id)
url_base="https://music.163.com/song/media/outer/url?id="
music=requests.get(url_base+music_id,headers=headers)
#print(url_base+music_id)
with open('./music/'+music_name+'.mp3','wb') as file:
file.write(music.content)
print(music_name+'下载成功') 网易云的得使用外链 {:5_108:} wp231957 发表于 2022-7-25 17:42
网易云的得使用外链
怎么知道外链的地址,用浏览器插件抓吗还是其他办法 Eric... 发表于 2022-8-2 00:22
怎么知道外链的地址,用浏览器插件抓吗还是其他办法
你可以百度一下,我发现我说的外链和他们说的外链,不在一个频道上 Traceback (most recent call last):
File "C:/Users/wei/Desktop/网易云.py", line 20, in <module>
with open('./music/'+music_name+'.mp3','wb') as file:
FileNotFoundError: No such file or directory: './music/若把你.mp3'为啥显示是这样的
qwq
页:
[1]