# coding=gbkimport Requestsimport jsonc= ' netease cloud reptile Combat One ' print (c) music_url = ' https://music.163.com/#/song?id=28815250 ' id = Music_url.split (' = ') [1]# print (id) url = ' https://music.163.com/weapi/v1/resource/comments/R_SO_4_%s?csrf_token= 7e19029fe28aa3e09cfe87e89d2e4eeb '% (id) headers = {' user-agent ': ' mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/55.0.2883.87 safari/537.36 ', ' Referer ': ' Https://music.163.com/so ng?id=%s '% (ID), ' Origin ': ' https://music.163.com ',}formdata = {' params ': ' Aof/zxuccqvtacmcphecfgvpfrbtdj4jfpjs az3tyn9j+r0ncnkphzdvecdz/jm+1cpa+byvao2j9d44b/mg97whjmxwkfo4tm++ afybgk11nnsbksuq5bxjr6ye0myfhu8spq7wb9diupfks2ulw0gxwu/il1ns/elrq+bbyikk/cyne90s/ Ygs6ldxpbcnd1yqtuol176abzxtjecgkfbxy+mlkcwscacck1s3sto= ', ' encseckey ': ' 365b4c31a9c7e2ddc002e9c42942281d7e450e5048b57992146633181efe83c1e26acbc8d84b988d746370d788b6ae087547bace402565cca3ad59ccc Cf7566b07d364aa1d5b2bbe8ccf2bc33e0f03182206e29c66ae4ad6c18cb032d23f1793420ceda05e796401f170dbdb825c20356d27f07870598b2798f8d344807ad6f2 ',}response = requests.post (url, headers = headers, data = Formdata) Messa GES = Json.loads (response.text) data_list=[]data={}for message in messages[' hotcomments ']:d ata[' nickname ']=message[' User ' [' nickname ']data[' content ']=message[' content ']data_list.append (data) data={} #print (data_list) for I in Data_ List:c = ' +i[' nickname ']+ ': ' +i[' content ']print (' \ n ' +c.replace (' \ n ', ') ')
Summarize:
1. The first line of "# CODING=GBK" indicates that a text string can be entered in a text editor.
2, "id = music_url.split (' = ') [1]" in the split () function represents the grouping of elements, in the example "https://music.163.com/#/song?id=", "28815250 "
3. The HTML text obtained by the requests module needs to be converted to Python-readable text using the Json.loads () method, otherwise it will be an error. This is not the case in Jupyter notebook.
4. The replace () function removes the elements in the string, and the newline character becomes empty.
The final display results are as follows:
This article introduced the NetEase Cloud Music review Crawl the related content, please follow the PHP Chinese network.