gyc666
发表于 2022-10-2 19:10:10
1
rubidam
发表于 2022-10-2 20:49:59
厉害厉害厉害厉害厉害厉害厉害厉害厉害厉害
rubidam
发表于 2022-10-2 20:51:07
import requests,re,random
class Music_163(object):
def__init__(self,url,id,cookie):
self.url=url
self.headers={
"user-agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3947.100 Firefox/73.0 Safari/537.36",
"Host": "music.163.com",
"Upgrade-Insecure-Requests": "1"
}
self.headers["cookie"]=cookie
self.params={"id":id}
def getresponse(self):
response=requests.get(self.url,params=self.params,headers=self.headers)
response.encoding="utf-8"
return response.text
def getsongids(self):
return re.findall(r'<a href="(/song\?id=\d+)">(.*?)</a>', self.getresponse())
def save(self):
xh=1
songid=self.getsongids()
for x in songid:
mp3url="https://link.hhtjim.com/163/"+x.split("=")[-1]+".mp3"
mp3data=requests.get(mp3url).content
#filename=x.replace("*","").replace("?","").replace("'","").replace('"',"").replace("/","").replace("","").replace(""|","").replace("<","").replace(":","").replace(">","").replace(":","")
filename=x.translate(str.maketrans("", "", "*?'"/\\|<:>:"))
if filename=="" or filename==" ":
filename=random.sample("abcdefghijklmnopqrstuvwxyz0123456789",8)
with open(filename+".mp3","wb") as f:
print(str(xh)+":"+x)
f.write(mp3data)
xh+=1
#歌手孙楠专辑
id=4941
url="https://music.163.com/artist"
cookie="JSESSIONID-WYYY=Mx9T49ZPy8lCDM6oPWwiFTc1%2BSjeGm%5CqiHf%2FRwh32Oq2zESSy4z4ev%5CH0HQsPQmD3JpINDUNUM1xeT6rU9aEn%2Bf%5Cn9IC%2FBnXV%5C8AG8BgSJnTjxN%5C%2B8ZmizAg86wOnW%2F2j6ED%2BNsBz8uKFx%2FH%2BhqGc3lK6VyHTCwqPH4pCF3UJ%2BozjP6M%3A1583462789740; _iuqxldmzr_=32; _ntes_nnid=16e9bfe56d5ee8387ee957afbedb11de,1583459249711; _ntes_nuid=16e9bfe56d5ee8387ee957afbedb11de; WM_NI=BxJfR3LE0Q1p8lJyWMX7YqphK12J2zWA3sVqjmGEyxZ5VwzHsOhL34710TiLuUSeli76%2B%2FtTccDbk7L0nnnf%2FCTVEYQneKOnozFlx2mpkQrDgm11QN2FAxEASBtJk1PddWk%3D; WM_NIKE=9ca17ae2e6ffcda170e2e6eed4cf39ab87a78bf667b79e8bb6d14a939e9abaf45b9ab7a799d7729bb0a898fb2af0fea7c3b92a82a88687d139909b00b2b47cfcb4869ad6479ce99792f36489effeabb172959ffd94d57baab389a6fc749aeb9a98f944b191a8adb240f5ef00b5ec48b78b9d86ef63f5eae5d0f760a1bd8c83ea3d90f0a28fed6eed9d9cb7c85393b2abacce66ada68a8dfb3aafb0a5b2f150a5b3ffd2d446f29a8f99c84b919ebcabea3b94bcacb8ea37e2a3; WM_TID=kixBNykIgcZEUBEBEBN7FI3n0HmM9kxw"
musics=Music_163(url,id,cookie)
musics.save()
#民谣精选
id=974763910
url="https://music.163.com/playlist"
cookie="_iuqxldmzr_=32; _ntes_nnid=736a7c91871a79dd11dced78a8dee6d2,1583398122992; _ntes_nuid=736a7c91871a79dd11dced78a8dee6d2; WM_TID=H7lwhcJ3P%2FBABRAUERJvUNyWqEL%2BaeQj; WM_NI=PPSsUwqHRIikER4rpnsbHjNgbWcra2w41a6EZ2QLSlfjBOBHLZdTs0Q6dYYV8ot1RlT3epQ9GdcAUkh8LU%2F3dywrOBWYcCr4gcg4B7HMZEA2DpamJcOtPKO1aLIUjcNnb3g%3D; WM_NIKE=9ca17ae2e6ffcda170e2e6eea2d63c959e83cce6728aef8aa2d54e968e8ebbb54ba8edfba8cd4f93eba7b2e42af0fea7c3b92a94909d94d87db3989eaaec61878efc93f366b1be888bcd6da289ad93e43ab5ecff82b54f9aee9fadd268a6b68eb0c1449086acb5f23c93eaacbadc5efcb1bcd2d16898edab91d43385bcada2d861ace884b6ae39a8a7b993ce4a9587ada4f140a5bda9d5c13d8c9396a6c43a88b0af8ec9698daca0acce3ba39487b6e9698eb2aed4e637e2a3; JSESSIONID-WYYY=bDzRU2gcnc9nbI1Enq%2Fi2KR1p7%2B4svaEEhx8p1aUJZn4v8Ev67nkz%2FSjknJmmY23RHulqxMa7v6DmBksPMVKmzQwMAtq%2BoWZtEukRkqMKOOTFy6%2FBerUn9SsdABPIeGpUNOAPREQaSnQ4jqGd5J%2F%5CEof01YzIv%2BRZ3ZU836vAGyNHE0n%3A1583503014783"
musics=Music_163(url,id,cookie)
musics.save()
#飙升榜
id=19723756
url="https://music.163.com/discover/toplist"
cookie="_iuqxldmzr_=32; _ntes_nnid=736a7c91871a79dd11dced78a8dee6d2,1583398122992; _ntes_nuid=736a7c91871a79dd11dced78a8dee6d2; WM_TID=H7lwhcJ3P%2FBABRAUERJvUNyWqEL%2BaeQj; WM_NI=PPSsUwqHRIikER4rpnsbHjNgbWcra2w41a6EZ2QLSlfjBOBHLZdTs0Q6dYYV8ot1RlT3epQ9GdcAUkh8LU%2F3dywrOBWYcCr4gcg4B7HMZEA2DpamJcOtPKO1aLIUjcNnb3g%3D; WM_NIKE=9ca17ae2e6ffcda170e2e6eea2d63c959e83cce6728aef8aa2d54e968e8ebbb54ba8edfba8cd4f93eba7b2e42af0fea7c3b92a94909d94d87db3989eaaec61878efc93f366b1be888bcd6da289ad93e43ab5ecff82b54f9aee9fadd268a6b68eb0c1449086acb5f23c93eaacbadc5efcb1bcd2d16898edab91d43385bcada2d861ace884b6ae39a8a7b993ce4a9587ada4f140a5bda9d5c13d8c9396a6c43a88b0af8ec9698daca0acce3ba39487b6e9698eb2aed4e637e2a3; JSESSIONID-WYYY=bDzRU2gcnc9nbI1Enq%2Fi2KR1p7%2B4svaEEhx8p1aUJZn4v8Ev67nkz%2FSjknJmmY23RHulqxMa7v6DmBksPMVKmzQwMAtq%2BoWZtEukRkqMKOOTFy6%2FBerUn9SsdABPIeGpUNOAPREQaSnQ4jqGd5J%2F%5CEof01YzIv%2BRZ3ZU836vAGyNHE0n%3A1583503014783"
musics=Music_163(url,id,cookie)
musics.save()
zjk520
发表于 2022-10-6 17:02:59
学习学习
Haochin
发表于 2022-10-6 17:21:46
康康
雾云ya
发表于 2022-10-11 17:34:39
4
xuemu
发表于 2022-11-11 19:53:55
1
LPIU
发表于 2022-11-17 19:25:14
666
navi
发表于 2022-11-28 20:37:01
66666
wzliuli
发表于 2022-11-28 22:37:51
运行时提示:SyntaxError: unexpected character after line continuation character
这是什么问题?
17704903344
发表于 2022-11-28 22:45:23
666
回家修别墅啊
发表于 2023-2-10 15:55:02
看看
pi123
发表于 2023-2-12 12:55:18
学习一下
编程的小杰
发表于 2023-3-4 00:12:36
这好用么?
itzyx
发表于 2024-9-27 23:23:26
看看学习一下