0
点赞
收藏
分享

微信扫一扫

爬虫学习:爬取网易云免费歌曲

闲来没事贴个小代码
代码:

import requests
from bs4 import BeautifulSoup
url = 'https://music.163.com/artist?id=3684'
headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36 SLBrowser/7.0.0.4071 SLBChan/30'}
resp = requests.get(url,headers=headers)
soup = BeautifulSoup(resp.text, 'html.parser')
inf = soup.find('ul',class_='f-hide')
information = inf.find_all('a')
number = 0
path='D://code//my python code//爬虫//shipin//'
for i in information:
number=number+1
name=i.text
newname=name+'.mp3'
web=i.get('href')
url='https://music.163.com/song/media/outer/url?'+web
url = url.replace('/song?', '')
response = requests.get(url=url, headers=headers) # 在此发送新的请求
# print(name)
print(url)
with open(path+newname,'wb') as f:
f.write(response.content)
print("%s下载成功" % newname)

成功:
爬虫学习:爬取网易云免费歌曲_safari
其实挺简单的,没啥好说的
有问题留言or加群:970353786


举报

相关推荐

java爬取网易云音乐评论

0 条评论