-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscript.py
31 lines (23 loc) · 949 Bytes
/
script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os
import json
import requests
from bs4 import BeautifulSoup
headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",
"X-Real-IP": "211.161.244.70"}
def get_music_u():
music_u = os.environ.get("MUSIC_U", None)
assert music_u is not None, "Set MUSIC_U in environment variables first!"
return music_u
def run():
music_u = get_music_u()
s = requests.Session()
s.cookies.set("MUSIC_U", music_u, domain=".music.163.com")
r = s.get("https://music.163.com/discover/toplist", headers=headers)
html = BeautifulSoup(r.text, "html.parser")
songs = json.loads(html.find(id="song-list-pre-data").text)
assert len(songs), "Failed to obtain toplist!"
print(len(songs))
r = s.post("https://music.163.com/weapi/login/token/refresh")
print(r.status_code)
if __name__ == "__main__":
run()