import requests
import re
# 张学友:aHNj
# 陈奕迅:eG4
# 林忆莲:d2t3eA
name = input()
# url = 'http://www.2t58.com/so/{}/1.html'.format(name)
url = 'http://www.2t58.com/singer/{}/1.html'.format(name)
response = requests.get(url = url)
ex = '<div class="name"><a href="/song/(.*?).html" target="_mp3">.*?</a></div>'
musicIndex = re.findall(ex, response.text, re.S)
smallmusicList = []
for j in range(0, 6):
smallmusicList.append(musicIndex[j])
print(smallmusicList)
headers ={
'Accept':'application/json, text/javascript, */*; q=0.01',
'Accept-Encoding':'gzip, deflate',
'Accept-Language':'zh-CN,zh;q=0.9',
'Connection':'keep-alive',
'Content-Length':'26',
'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
'Cookie':'Hm_lvt_b8f2e33447143b75e7e4463e224d6b7f=1690974946; Hm_lpvt_b8f2e33447143b75e7e4463e224d6b7f=1690976158',
'Host':'www.2t58.com',
'Origin':'http://www.2t58.com',
'Referer':'http://www.2t58.com/song/bWhzc3hud25u.html',
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36',
'X-Requested-With':'XMLHttpRequest'
}
for i in smallmusicList:
data = {'id': i,'type': 'music'}
url2 = 'http://www.2t58.com/js/play.php'
response2 = requests.post(url = url2, headers = headers, data = data)
json_data = response2.json()
musicList = json_data['url']
musicResponse = requests.get(url = musicList)
filename = json_data['title'] + '.mp3'
with open('E:/music/' + filename, 'wb') as f:
f.write(musicResponse.content)
print(filename + '下载成功!')
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
音乐爬虫.rar (1个子文件)
音乐爬虫.py 2KB
共 1 条
- 1
资源评论
务农在家
- 粉丝: 39
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功