闲来没事贴个小代码 代码:
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)
成功:
其实挺简单的,没啥好说的 有问题留言or加群:970353786