Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use JS inverse method

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to use JS reverse method". In daily operation, I believe many people have doubts about how to use JS reverse method. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to use JS reverse method"! Next, please follow the editor to study!

Effect picture:

Is a html table, familiar with should be able to see directly, and then there are img tags, a tags and so on.

Page analysis:

When we use a chrome browser (Google is recommended) to go to the official website of NetEYun and find a song you like.

Turn on the F12 function, click XHR filter, at this time, we click play, on the right side will re-capture the new web request, including the song file link we need. Like this.

V1?csrf... This URL is just brushed, you can see in the response, there is a url, you copy it and open it, you can play it directly. Let's click headers to see how to send it.

Request url is requested and sent with post. Below are two parameter forms params and encSecKey. It seems that we can send the request directly with the following two parameters, so we just give it a try.

Def spider (self): this is the way to climb a song Copy params and you can send the request "" r = requests.post (self.params_url, params=self.params) if r.status_code = 200: mp3 = r.json () .get ("data") [0] .get ("url") rmp3 = requests.get (mp3, headers= {"user-agent": self.ua}) if rmp3.status_code = 200: with open ("like fish .mp3" 'wb') as Fw:; fw.write (rmp3.content) print (download succeeded)

Finally, it was successfully downloaded.

In other words, we only need to know where these two parameters come from, we can construct them ourselves, and we can do whatever we want. At this time, we can turn on the debugging function that comes with the browser. To break the point, to debug, how to play, how to break? Just take a closer look at the notes on my picture.

Or the previous package, you click on the fourth initiator will refresh a lot of files related to it, we click on the first one.

And then come to this, remember the previous two parameters, here we directly ctrl + f to find one of the parameters.

Here you can see that params and encSecKey are all based on bvz7s, while bvz7s is based on the window.asrsea () function, so make a breakpoint in this function and move on to the next search point.

Here, we find that window.asrsea equals d, so we have to look at the d function, and in the tone of the d function, we can all hit a breakpoint so that we can see clearly. After turning on the power outage, refresh the page and wait for a while.

Then go to the first breakpoint, and then f8 jumps to the next breakpoint.

Then we can find out what the four parameters accepted by d are. (d, e, f, g) on the right, we can also see that many tests have found that the last three are encryption parameters, fixed values, so copy them and take them for use. For the first d = {"csrf_token": "…" This is used to record whether you have logged in to your account. If you do not log in, it is empty.

Continue f8 jump to the end

It is found that we can just take the first four parameters and then go through the a, b, b, c functions. Later we will see what each function does, which involves their encryption methods. But here, we need to think about a problem. With regard to the first four parameters, only one d will change, nothing else will change, and d is still an empty or messy number. Then how does he know which song I am? Which singer, so there must be something wrong with this parameter. (after encryption testing, it is found that the length of the parameter after encryption is much shorter.) so here I continue to debug the same operation.

Debug a circle, and finally have a reliable, there is a song id and the sound quality of the song, other, if not familiar, you can try every d, until the encryption parameters are correct.

So first make sure that d is

"{" ids ":" [1459950258] "," level ":" standard "," encodeType ":" aac "," csrf_token ":" 59098e191e8babbaef83f1b8bbbe5987 "}"

Let's use this d parameter to encrypt it once.

Parameter encryption:

Going back to the area of the previous d function, which is just above d, we can see the execution of the amemery bpenary c function.

We just need to understand it one by one and then convert it in python language. Let's talk about this in modules.

Function function A:function a (a) {var d, e, b = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", c = ""; for (d = 0; a > d; d + = 1) e = Math.random () * b.length, e = Math.floor (e), c + = b.charAt (e); return c}

As you can see at a familiar glance, the a function accepts a parameter, and then in another loop, the loop is a time, and then some characters are randomly selected from b, and finally returned in the form of a string. Random is not so easy for Javascript, he needs to generate (0,1) numbers with random, and then zoom in, round, take values, and accumulate, but for python, it is as follows:

Def SimulateFunctionA (self, length=None): "@ JavaScript function a (a) {var d, e, b =" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ", c ="; for (d = 0; a > d; d + = 1) e = Math.random () * b.length, e = Math.floor (e), c + = b.charAt (e) Return c} length: 16 using the python get the c "b = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' c = random.sample (b, length) return".join (c)

simple。

Function function B:function b (a, b) {var c = CryptoJS.enc.Utf8.parse (b), d = CryptoJS.enc.Utf8.parse ("0102030405060708"), e = CryptoJS.enc.Utf8.parse (a), f = CryptoJS.AES.encrypt (e, c, {iv: d, mode: CryptoJS.mode.CBC}); return f.toString ()}

This is an AES encryption, mode CBC, in fact, at the beginning I do not know what AES encryption is, later I looked at the official website documents, referred to other methods, implemented.

If you look at this function, you accept aforme b, where what aforme b is can be seen in function d.

According to the previous analysis, g is a fixed value, which we have copied down, and d thinks it is a character dictionary.

"{" ids ":" [1459950258] "," level ":" standard "," encodeType ":" aac "," csrf_token ":" 59098e191e8babbaef83f1b8bbbe5987 "}"

So, let's add these parameters in python language and try to simulate them.

Def SimulateFunctionB (self, d, key): "" function b (a, b) {var c = CryptoJS.enc.Utf8.parse (b), d = CryptoJS.enc.Utf8.parse ("0102030405060708"), e = CryptoJS.enc.Utf8.parse (a), f = CryptoJS.AES.encrypt (e, c, {iv: d) Mode: CryptoJS.mode.CBC}) Return f.toString ()} a = `"{" ids ":" [1459950258] "," level ":" standard "," encodeType ":" aac "," csrf_token ":" 59098e191e8babbaef83f1b8bbbe5987 "}" `b = key= self.g (first) = SimulateFunctionA () (second) "key= key.encode () iv = self.iv.encode () aes = AES.new (key=key, mode=AES.MODE_CBC) Iv=iv) text= pad (data_to_pad=d.encode (), block_size=AES.block_size) aes_text = aes.encrypt (plaintext=text) aes_texts = base64.b64encode (aes_text). Decode () return aes_texts SimulateFunticonB (d = "`" {"ids": "[1459950258]", "level": "standard", "encodeType": "aac", "csrf_token": "59098e191e8babbaef83f"

Here is also a successful realization, I forgot to take a screenshot. About how to encrypt AES, you can read mine directly, and those who have time and interest can also read the official website documents like me. It's all right, just make it happen.

Function function C:function c (a, b, c) {var d, e; return setMaxDigits (131), d = new RSAKeyPair (b, ", c), e = encryptedString (d, a)}

At first glance, it is very simple, but it is actually complicated. I used the RSA encryption algorithm. I found some information about the RSA encryption algorithm.

The general principle is as shown in the figure:

Reference documentation

We use python to do this.

Def SimulateFunctionC (self, random16): "" a = 131RSA encryption principle # num = pow (x, y)% z # encryption C = me ^ e mod n "e = self.e f = self.f text = random16 [::-1] num = pow (int (text.encode (). Hex (), 16), int (e, 16), int (f, 16) return format (num) Zfill (131) # TODO: last the num change the hex digit and left fill (131)

In fact, pow () can accept three parameters. If there is a third, the third is the residual value. With int (a, 16), you can directly convert hexadecimal to decimal, and the final format (num,'x') outputs the value in hexadecimal form, and then zfill () fills 131digits, (it is known from function C that the number of digits is 131b)

Coherent encryption function class:

Analysis of the above three functions, in fact, we can directly write the program encryption, we connect the program.

#-*-coding: utf-8-*-# @ Time: 2020-9-15 15:45 # @ author: the hourglass is raining # @ Software: PyCharm# @ CSDN: https://me.csdn.net/qq_45906219import requestsfrom get_useragent import GetUserAgentCSimport randomfrom Crypto.Util.Padding import padfrom Crypto.Cipher import AESimport base64class GetParams (object): def _ _ init__ (self): self.ua = GetUserAgentCS (). Get_user () self.params_url = 'https://music.163.com/weapi/song/enhance/player/url/v1?csrf_token=' self.e = "010001" self.g = "0CoJUm6Qyw8W8jud" self.iv =' 0102030405060708' self.f = "00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a"\ "876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9"\ "d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e28"\ "9dc6935b3ece0462db0a22b8e7" self.params = None def SimulateFunctionA (self Length=None): "@ JavaScript function a (a) {var d, e, b =" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ", c =" For (d = 0; a > d; d + = 1) e = Math.random () * b.length, e = Math.floor (e), c + = b.charAt (e) Return c} length: 16 using the python get the c "" b = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' c = random.sample (b, length) return "" .join (c) def SimulateFunctionB (self, d, key): "function b (a, b) {var c = CryptoJS.enc.Utf8.parse (b) D = CryptoJS.enc.Utf8.parse ("0102030405060708"), e = CryptoJS.enc.Utf8.parse (a), f = CryptoJS.AES.encrypt (e, c, {iv: d, mode: CryptoJS.mode.CBC}) Return f.toString ()} a = "{" csrf_token ":"} "b = key= self.g (first) = SimulateFunctionA () (second)" key= key.encode () iv= self.iv.encode () aes = AES.new (key=key, mode=AES.MODE_CBC, iv=iv) text = pad (data_to_pad=d.encode ()) Block_size=AES.block_size) aes_text = aes.encrypt (plaintext=text) aes_texts = base64.b64encode (aes_text). Decode () return aes_texts def SimulateFunctionC (self, random16): "" a = 131RSA encryption principle # num = pow (x Y)% z # encryption C = M ^ e mod n "" e = self.e f = self.f text = random16 [::-1] num = pow (int (text.encode (). Hex (), 16), int (e, 16), int (f, 16) return format (num Zfill (131) # TODO: last the num change the hex digit and left fill (131) def spider (self): "" this is the way to climb a song. Copy params to send the request "" r = requests.post (self.params_url, params=self.params) if r.status_code = 200: mp3 = r.json () .get ("data") [0] .get ("url") rmp3 = requests.get (mp3) Headers= {"user-agent": self.ua}) if rmp3.status_code = = 200: with open ("like fish .mp3", 'wb') as Fw: Fw.write (rmp3.content) print ("download succeeded") def get_encrypt_params (self, d=None): "The function can encrypt your params if you give me a d @ params: d debug your chrome browser" I = self.SimulateFunctionA (length=16) encText = self.SimulateFunctionB (d, self.g) encText = self.SimulateFunctionB (encText) I) encSecKey = self.SimulateFunctionC (random16=i) return {"params": encText, "encSecKey": encSecKey} # a = GetParams () # a.spider ()

In the final analysis, we still want the id of the song, how come, we need to continue to watch.

ID acquisition: get a free single ID:

Just do it this way.

Get the id list:

If you enter the singer form in this interface, you can't find the id form data you need, so here you need to crawl it with selenium and analyze it.

You can find id form data if you do the following.

And again, in this package, we see that the parameters are still params and encSerKey, and then repeat the above operation, break point debugging, and even encryption in the same way, constantly breaking points, and finally find that d is like this.

{"hlpretag": "," hlposttag ":", "s": "Xu Song", "type": "1", "offset": "0", "total": "true", "limit": "30", "csrf_token": ""}

We can change the value of s, the song name singer can, build this dictionary, send this URL, you can get id, and then take the id to continue to construct the above d value, you can get the song url.

As follows:

#-*-coding: utf-8-*-# @ Time: 2020-9-17 14:59 # @ author: the hourglass is raining # @ Software: PyCharm# @ CSDN: https://me.csdn.net/qq_45906219from GetParamsimport GetParamsimport requestsfrom get_useragent import GetUserAgentCSimport randomimport keyringimport yagmailclass DownMp3 (object): def _ _ init__ (self): self.GetIdUrl = "https://music.163 .com / weapi/cloudsearch/get/web?csrf_token= "self.GetMP3Url = 'https://music.163.com/weapi/song/enhance/player/url/v1?csrf_token=' self.ua = GetUserAgentCS (). Get_user () self.headers = {" User-Agent ": self.ua} self.MUSIC_LIST = [] # The singer music demo list self.Sented_qq_email = self.get_ Email () def get_email (self): email_list = input ("enter QQ Mail if you have more than one, please separate them with a space:"). Split () if len (email_list) = = 1: if "@ qq.com" not in email_list [0]: raise Exception ("the mailbox specification does not seem to be appropriate You typed ", email_list [0]) else: return email_list [0] elif len (email_list) > = 2: for i in email_list: if" @ qq.com "not in i: raise Exception (" the mailbox specification does not seem appropriate. You typed ", I) else: pass return email_list def my_request (self, url, model=" get ", params=None): if model= = 'post': r = requests.post (url, headers=self.headers) Params=params) if r.status_code = 200: r.encoding = r.apparent_encoding s = r.json () return s elif model = 'get': r = requests.get (url, headers=self.headers) Params=params) if r.status_code = = 200: return r.content else: raise Exception ("method is error!") Def get_mp3_id_demo (self, start=None): "get the mp3 id {" hlpretag ":", "hlposttag": "," s ":" Ben "," type ":" 1 "," offset ":" 0 "," total ":" true "," limit ":" 30 "," csrf_token ":"} "" if start is None: raise Exception ("You should enter a start name" But you enter start = ", start) d = {" hlpretag ":", "hlposttag": "," s ": str (start)," type ":" 1 "," offset ":" 0 "," total ":" true "," limit ":" 30 " "csrf_token": "} params= GetParams (). Get_encrypt_params (str (d)) return self.my_request (self.GetIdUrl, model=" post ", params=params) [" result "] [" songs "] def get_mp3_url (self, id):"params: id the music of id fix the id into" {"ids": "[35440198]" "level": "standard", "encodeType": "aac", "csrf_token": ""} "so we can get the music the downpath"d = {" ids ": str ([id])," level ":" standard "," encodeType ":" aac "," csrf_token ":"} params = GetParams (). Get_encrypt_params (str (d)) context = self.my_request (self.GetMP3Url) Model= "post", params=params) mp3_path_url = context.get ("data") [0] ["url"] return mp3_path_url def print_id_list (self, id_list): "" params: id_list print the singer about 30s musics "" a = {} for index Value in enumerate (id_list): a ['count'] = (index + 1) a ["singer_name"] = value.get ("name") a ["id"] = value.get ("id") a ["album"] = value.get ("al"). Get ("name") a ["image"] = value.get ("al") .get ("picUrl") self.MUSIC_LIST.append (a.copy ()) def random_get_mp3 (self): mp3Ten = random.sample (self.MUSIC_LIST) 10) # Ten songs content = "" # write data into html to facilitate sending content + ='

Happy day for you!

'content + ='\ nToday music demo\ nMeitu 'count = 1 for j in mp3Ten: s = f "\ n {count} {j [' singer_name']}"\ f "Click to play {j ['album']}"\ f "

美图

"content + = s count + = 1 content + ="return content def sent_email (self, content):" sent the music demo list for you like one "" pwd = keyring.get_password ("qqemail", "884427640") yag = yagmail.SMTP ("884427640@qq.com", pwd) Host= "smtp.qq.com") # test qq 2817634007@qq.com yag.send (self.Sented_qq_email, 'NetEase exclusive push', content) yag.close () print ("Today music already sent ok!") Def start_demo (self): try: start_name = input ("input a music singer or music name"if you like it:") id_list = self.get_mp3_id_demo (start=start_name) self.print_id_list (id_list) print (self.MUSIC_LIST) Self.sent_email (self.random_get_mp3 ()) except Exception as e: print ("error appears" E, "try again!") Self.start_demo () # if you want to run this program, open the following note # a = DownMp3 () # a.start_demo () to send the mailbox:

The function library uses

Import keyring

Import yagmail

Just download it.

About keyring, this is a library that holds passwords. For some passwords, we can do this.

Keyring set qq 88442764 then asks you to enter your password, and when you type in to get keyring get qq 884427640, it's OK if your keyring.exe is in the environment variable, and of course in python, this is also very easy to use.

About yagmail, this is a function library that sends mailboxes.

Def sent_email (self, content): "" sent the music demo list for you like one "pwd = keyring.get_password (" qqemail "," 884427640 ") yag = yagmail.SMTP (" 884427640@qq.com ", pwd, host=" smtp.qq.com ") # test qq 2817634007@qq.com yag.send (self.Sented_qq_email, 'NetEase exclusive push' Content) yag.close () print ("Today music already sent ok!")

Pwd this is the authorization code of QQ Mail of the mailbox, a very long string, I want to go to QQ Mail to open the service, so I put it in the password library, and then use SMTP to link to the mailbox, and send it in this way.

Send the form:

Anyone who knows a little bit about html should be able to write this.

Just write it down like this. Send the full code: #-*-coding: utf-8-*-# @ Time: 2020-9-17 14:59 # @ author: the hourglass is raining # @ Software: PyCharm# @ CSDN: https://me.csdn.net/qq_45906219from GetParamsimport GetParamsimport requestsfrom get_useragent import GetUserAgentCSimport randomimport keyringimport yagmailclass DownMp3 (object): def _ _ init__ (self): self.GetIdUrl = " Https://music.163.com/weapi/cloudsearch/get/web?csrf_token=" self.GetMP3Url = 'https://music.163.com/weapi/song/enhance/player/url/v1?csrf_token=' self.ua = GetUserAgentCS (). Get_user () self.headers = {"User-Agent": self.ua} self.MUSIC_LIST = [] # The singer music demo list self.Sented_qq _ email = self.get_email () def get_email (self): email_list = input ("enter QQ Mail if you have more than one, please separate them with a space:"). Split () if len (email_list) = = 1: if "@ qq.com" not in email_list [0]: raise Exception ("the mailbox specification does not seem to be appropriate You typed ", email_list [0]) else: return email_list [0] elif len (email_list) > = 2: for i in email_list: if" @ qq.com "not in i: raise Exception (" the mailbox specification does not seem appropriate. You typed ", I) else: pass return email_list def my_request (self, url, model=" get ", params=None): if model= = 'post': r = requests.post (url, headers=self.headers) Params=params) if r.status_code = 200: r.encoding = r.apparent_encoding s = r.json () return s elif model = 'get': r = requests.get (url, headers=self.headers) Params=params) if r.status_code = = 200: return r.content else: raise Exception ("method is error!") Def get_mp3_id_demo (self, start=None): "get the mp3 id {" hlpretag ":", "hlposttag": "," s ":" Ben "," type ":" 1 "," offset ":" 0 "," total ":" true "," limit ":" 30 "," csrf_token ":"} "" if start is None: raise Exception ("You should enter a start name" But you enter start = ", start) d = {" hlpretag ":", "hlposttag": "," s ": str (start)," type ":" 1 "," offset ":" 0 "," total ":" true "," limit ":" 30 " "csrf_token": "} params= GetParams (). Get_encrypt_params (str (d)) return self.my_request (self.GetIdUrl, model=" post ", params=params) [" result "] [" songs "] def get_mp3_url (self, id):"params: id the music of id fix the id into" {"ids": "[35440198]" "level": "standard", "encodeType": "aac", "csrf_token": ""} "so we can get the music the downpath"d = {" ids ": str ([id])," level ":" standard "," encodeType ":" aac "," csrf_token ":"} params = GetParams (). Get_encrypt_params (str (d)) context = self.my_request (self.GetMP3Url) Model= "post", params=params) mp3_path_url = context.get ("data") [0] ["url"] return mp3_path_url def print_id_list (self, id_list): "" params: id_list print the singer about 30s musics "" a = {} for index Value in enumerate (id_list): a ['count'] = (index + 1) a ["singer_name"] = value.get ("name") a ["id"] = value.get ("id") a ["album"] = value.get ("al"). Get ("name") a ["image"] = value.get ("al") .get ("picUrl") self.MUSIC_LIST.append (a.copy ()) def random_get_mp3 (self): mp3Ten = random.sample (self.MUSIC_LIST) 10) # Ten songs content = "" # write data into html to facilitate sending content + ='

Happy day for you!

'content + ='\ nToday music demo\ nMeitu 'count = 1 for j in mp3Ten: s = f "\ n {count} {j [' singer_name']}"\ f "Click to play {j ['album']}"\ f "

美图

"content + = s count + = 1 content + ="return content def sent_email (self, content):" sent the music demo list for you like one "" pwd = keyring.get_password ("qqemail", "884427640") yag = yagmail.SMTP ("884427640@qq.com", pwd) Host= "smtp.qq.com") # test qq 2817634007@qq.com yag.send (self.Sented_qq_email, 'NetEase exclusive push', content) yag.close () print ("Today music already sent ok!") Def start_demo (self): try: start_name = input ("input a music singer or music name"if you like it:") id_list = self.get_mp3_id_demo (start=start_name) self.print_id_list (id_list) print (self.MUSIC_LIST) Self.sent_email (self.random_get_mp3 ()) except Exception as e: print ("error appears" E, "try again!") Self.start_demo () # if you want to run this program, please open the following note # a = DownMp3 () # a.start_demo () def random_get_mp3 (self): mp3Ten = random.sample (self.MUSIC_LIST, 10) # put forward ten songs content = "" # write data into html to facilitate sending content + ='

Happy day for you!

'content + ='\ nToday music demo\ nMeitu 'count = 1 for j in mp3Ten: s = f "\ n {count} {j [' singer_name']}"\ f "Click to play {j ['album']}"\ f "

美图

"content + = s count + = 1 content + ="return content"

Just write it down like this.

Send the full code: #-*-coding: utf-8-*-# @ Time: 2020-9-17 14:59 # @ author: the hourglass is raining # @ Software: PyCharm# @ CSDN: https://me.csdn.net/qq_45906219from GetParamsimport GetParamsimport requestsfrom get_useragent import GetUserAgentCSimport randomimport keyringimport yagmailclass DownMp3 (object): def _ _ init__ (self): self.GetIdUrl = " Https://music.163.com/weapi/cloudsearch/get/web?csrf_token=" self.GetMP3Url = 'https://music.163.com/weapi/song/enhance/player/url/v1?csrf_token=' self.ua = GetUserAgentCS (). Get_user () self.headers = {"User-Agent": self.ua} self.MUSIC_LIST = [] # The singer music demo list self.Sented_qq _ email = self.get_email () def get_email (self): email_list = input ("enter QQ Mail if you have more than one, please separate them with a space:"). Split () if len (email_list) = = 1: if "@ qq.com" not in email_list [0]: raise Exception ("the mailbox specification does not seem to be appropriate You typed ", email_list [0]) else: return email_list [0] elif len (email_list) > = 2: for i in email_list: if" @ qq.com "not in i: raise Exception (" the mailbox specification does not seem appropriate. You typed ", I) else: pass return email_list def my_request (self, url, model=" get ", params=None): if model= = 'post': r = requests.post (url, headers=self.headers) Params=params) if r.status_code = 200: r.encoding = r.apparent_encoding s = r.json () return s elif model = 'get': r = requests.get (url, headers=self.headers) Params=params) if r.status_code = = 200: return r.content else: raise Exception ("method is error!") Def get_mp3_id_demo (self, start=None): "get the mp3 id {" hlpretag ":", "hlposttag": "," s ":" Ben "," type ":" 1 "," offset ":" 0 "," total ":" true "," limit ":" 30 "," csrf_token ":"} "" if start is None: raise Exception ("You should enter a start name" But you enter start = ", start) d = {" hlpretag ":", "hlposttag": "," s ": str (start)," type ":" 1 "," offset ":" 0 "," total ":" true "," limit ":" 30 " "csrf_token": "} params= GetParams (). Get_encrypt_params (str (d)) return self.my_request (self.GetIdUrl, model=" post ", params=params) [" result "] [" songs "] def get_mp3_url (self, id):"params: id the music of id fix the id into" {"ids": "[35440198]" "level": "standard", "encodeType": "aac", "csrf_token": ""} "so we can get the music the downpath"d = {" ids ": str ([id])," level ":" standard "," encodeType ":" aac "," csrf_token ":"} params = GetParams (). Get_encrypt_params (str (d)) context = self.my_request (self.GetMP3Url) Model= "post", params=params) mp3_path_url = context.get ("data") [0] ["url"] return mp3_path_url def print_id_list (self, id_list): "" params: id_list print the singer about 30s musics "" a = {} for index Value in enumerate (id_list): a ['count'] = (index + 1) a ["singer_name"] = value.get ("name") a ["id"] = value.get ("id") a ["album"] = value.get ("al"). Get ("name") a ["image"] = value.get ("al") .get ("picUrl") self.MUSIC_LIST.append (a.copy ()) def random_get_mp3 (self): mp3Ten = random.sample (self.MUSIC_LIST) 10) # Ten songs content = "" # write data into html to facilitate sending content + ='

Happy day for you!

'content + ='\ nToday music demo\ nMeitu 'count = 1 for j in mp3Ten: s = f "\ n {count} {j [' singer_name']}"\ f "Click to play {j ['album']}"\ f "

美图

"content + = s count + = 1 content + ="return content def sent_email (self, content):" sent the music demo list for you like one "" pwd = keyring.get_password ("qqemail", "884427640") yag = yagmail.SMTP ("884427640@qq.com", pwd) Host= "smtp.qq.com") # test qq 2817634007@qq.com yag.send (self.Sented_qq_email, 'NetEase exclusive push', content) yag.close () print ("Today music already sent ok!") Def start_demo (self): try: start_name = input ("input a music singer or music name"if you like it:") id_list = self.get_mp3_id_demo (start=start_name) self.print_id_list (id_list) print (self.MUSIC_LIST) Self.sent_email (self.random_get_mp3 ()) except Exception as e: print ("error appears" E, "try again!") Self.start_demo () # if you want to run this program, please open the following note # a = DownMp3 () # a.start_demo () to download the single code:

Extended a code to download a song if you need it.

#-*-coding: utf-8-*-# @ Time: 21:35 on 2020-9-17 # @ author: the hourglass is raining # @ Software: PyCharm# @ CSDN: https://me.csdn.net/qq_45906219import requestsfrom get_useragent import GetUserAgentCSfrom GetParams import GetParamsfrom DownMp3 import DownMp3class DownOneMp3 (DownMp3): def _ init__ (self): super (). _ init__ () Self.GetIdUrl = "https://music.163.com/weapi/cloudsearch/get/web?csrf_token=" self.params_url =" https://music.163.com/weapi/song/enhance/player/url/v1?csrf_token=" self.headers = {"user-agent": GetUserAgentCS () .get_user ()} self.start = input ("Please input the music name:") ids = self.get _ id () self.params = self.get_params (id=ids) self.mp3_name = self.start + ".mp3" def my_request (self Url, model= "get", params=None): "" A method inheriting the parent class "" return super () .my_request (url, model, params) def get_params (self, id): "give id return encryption parameters"d = {" ids ": str ([id])," level ":" standard "," encodeType ":" aac " "csrf_token": "} params = GetParams () .get_encrypt_params (str (d)) return params def get_id (self):" get id based on the song name "" start = self.start d = {"hlpretag": "," hlposttag ":" "s": str (start), "type": "1", "offset": "0", "total": "true", "limit": "30" "csrf_token": "} params= GetParams (). Get_encrypt_params (str (d)) return self.my_request (self.GetIdUrl, model=" post ", params=params) [" result "] [" songs "] [0] .get (" id ") def spider (self):"this is the way to climb a song. You only need to enter the song name to automatically call other classes to implement parameters such as encryption, id acquisition, etc. "" import os r = requests.post (self.params_url). Params=self.params) if r.status_code = = 200: print (r.json ()) mp3 = r.json (). Get ("data") [0] .get ("url") print ("music link is", mp3) rmp3 = requests.get (mp3, headers=self.headers) if rmp3.status_code = 200: with open (self.mp3_name) 'wb') as Fw: Fw.write (rmp3.content) print ("Down Successful!", "file path is" Os.path.dirname (_ _ file__) # if you want to run this program, please open the following note # a = DownOneMp3 () # a.spider () about _ _ init__: "" if you just want to download a song and jump to the DownOneMp3 module startup module to run if you want to send more than one song to someone's mailbox to jump to the DownMp3 module startup module to run "" here " The study on "how to use the reverse method of JS" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report