Python crawler Instance--NetEase cloud Music leaderboard Crawler

Source: Internet
Author: User
Tags base64

NetEase Cloud Music, previously there is a JSON download API link, now no, only music id,title, only to see the playback request, but the playback request are encrypted values, good pit ...

In a variety of efforts, and finally found a great God wrote the blog, 3.6 version of the Python

Python perfect hack netease cloud music: 1190000012818254

Python code: Https://github.com/imyxuan/Netease

A variety of errors were encountered while running the code of the Great God:

   From Crypto.cipher import AES

Need to install: Pip Install Pycrypto

First Error: prompt does not install visual Studio Microsoft Build Tools 14.0

: https://www.microsoft.com/en-us/download/details.aspx?id=48159

Second error: Install vs also prompts the. NET Framework version to be low, and then installs version 4.6

: https://www.microsoft.com/en-us/download/details.aspx?id=48130

Third error: Using CMD to install pip install Pycrypto prompt cl.exe run does not work, continue to various Baidu, download a C + + repair software DirectX:

: Http://soft.duote.org/directx_3.7.zip

After the repair tool is run, the prompt C + + has an exception, need to extend the repair ..... Then the tools--and then the extension--extend. And then fix it again, prompting the C + + repair to succeed!!

Fourth time error: I thought this would be good, MMP, cmd run again error

intmax_t C:\Program Files (x86) \ Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.

Baidu only: 78470824, install this to get:

Solution:

1. Set the environment variable VCInstallDir variable value for Microsoft Visual Studio 14.0 C:\Program Files (x86) \microsoft Visual Studio 14.0\VC (the default installation location, according to your own Location of your own installation)

2. Execute the Vcvarsall.bat script in the installation path above

3. Execute set Cl=-fi "%vcinstalldir%\include\stdint.h" in command line (CMD)

4. Reinstall PIP Install Pycrypto

Finally installed successfully, and then the confidence to restart my pycharm, the result of running the time still can not find that crypto module, which is already in the past several hours have no way, can only Baidu.

Check the Python module installation directory, found that there is already a crypto, but the project does not load, should be the project inside the reference is not correct, sure enough, the project does not have that module, so, the installation of the crypto copy to the project directory, this time the perfect solution

Python's crypto installation directory: C:\Users\Administrator\AppData\Local\Programs\Python\Python36\Lib\site-packages

Python Module directory for the project:

      

Copy all site-packages files from the installation directory to the site-packages of the project, and it will be perfectly solved; Welcome to join qq:1095737364 QQ Group: 123300273

Here's the code:

#Coding:utf-8#1190000012818254 statement: It's written by this great God, and it doesn't matter, I just changed it. fromCrypto.cipherImportAESImportBase64ImportRequestsImportsysheaders= {    'Cookies':'appver=1.5.0.75771;',    'Referer':'http://music.163.com/',    'user-agent':'mozilla/5.0 (Windows NT 10.0; Win64; x64) applewebkit/537.36 (khtml, like Gecko) chrome/63.0.3239.132 safari/537.36'}first_param="{\ "ids\": \ "[%d]\", \ "br\": 128000,\ "csrf_token\": \ "\"}"Second_param="010001"Third_param="00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695 280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc693 5b3ece0462db0a22b8e7"Forth_param="0cojum6qyw8w8jud"defGet_params (): IV="0102030405060708"First_key=Forth_param Second_key= 16 *'F'H_enctext=Aes_encrypt (First_param, First_key, iv) H_enctext=Aes_encrypt (H_enctext, Second_key, iv)returnH_enctextdefGet_encseckey (): Encseckey="257348AECB5E556C066DE214E531FAADD1C55D814F9BE95FD06D6BFF9F4C7A41F831F6394D5A3FD2E3881736D94A02CA919D952872E7D0A50EBFA 1769a7a62d512f5f1ca21aec60bc3819a9c3ffca5eca9a0dba6d6f7249b06f5965ecfff3695b54e1c28f3f624750ed39e7de08fc8493242e26dbc4484 a01c76f739e135637c"    returnEncseckeydefaes_encrypt (text, key, iv): Pad= 16-len (text)% 16ifisinstance (text, str): Text= text + pad *chr (PAD)Else: Text= Text.decode ('Utf-8') + pad *chr (PAD) encryptor=aes.new (Key, AES. MODE_CBC, iv) Encrypt_text=encryptor.encrypt (text) Encrypt_text=Base64.b64encode (Encrypt_text)returnEncrypt_textdefGet_json (URL, params, encseckey): Data= {        "params": params,"Encseckey": Encseckey} response= Requests.post (URL, headers=headers, data=data). JSON ()returnresponse['Data']#List songs Batch download#r = requests.get (' http://music.163.com/api/playlist/detail?id=2884035 ') # NetEase original Song list#r = requests.get (' http://music.163.com/api/playlist/detail?id=19723756 ') # Cloud music Soaring list#r = requests.get (' http://music.163.com/api/playlist/detail?id=3778678 ') # Cloud Music hot song list#r = requests.get (' http://music.163.com/api/playlist/detail?id=3779629 ') # Cloud Music new song list#song single song batch Download#r = requests.get (' http://music.163.com/api/playlist/detail?id=123415635 ') # Cloud Music single--"Mandarin" Chinese wind rhythm, Chinese mark#r = requests.get (' http://music.163.com/api/playlist/detail?id=122732380 ') # Cloud Music song list-it's not love, it's just a lie of loneliness.R=requests.get ("http://music.163.com/api/playlist/detail?id=2884035", headers=headers) Arr=r.json () ['result']['Tracks'] forIinchRange (100): Toplistmp3id=str (arr[i]['ID']) Toplistmp3title= STR (arr[i]['name']) music_id=toplistmp3id First_param="{\ "ids\": \ "[%d]\", \ "br\": 128000,\ "csrf_token\": \ "\"}"%int (music_id) URL='https://music.163.com/weapi/song/enhance/player/url?csrf_token='params=get_params () Encseckey=Get_encseckey ()"""rsp:{' data ': [{' Gain ': 2.3073, ' type ': ' mp3 ', ' url ': ' Http://m10.music.1 26.net/20180111133509/24c79548414f7aa7407985818cb16a39/ymusic/333c/66b1/e5ec/72aeb13aca24c989295e58e8384e3 F97.mp3 ', ' MD5 ': ' 72aeb13aca24c989295e58e8384e3f97 ', ' flag ': 0, ' Code ': $, ' payed ': 0, ' id ': 15161 9, ' expi ':, ' size ': 3868307, ' uf ': None, ' BR ': 128000, ' fee ': 0, ' canExtend ': False}], ' Code ': $ """RSP=Get_json (URL, params, encseckey) Music_url= Rsp[0].get ('URL')    ifMusic_url:music=Requests.get (music_url) name= Sys.path[0] +"/mp3/%s.mp3"%Toplistmp3titlePrint(name) with open (name,"WB") as Code:code.write (music.content)#music_id = input (' Please enter song ID: ')

Python crawler Instance--NetEase cloud Music leaderboard Crawler

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.