代码拉取完成,页面将自动刷新
import time
import requests
url = 'https://music.163.com/weapi/cloudsearch/get/web?csrf_token='
fromData = {
'params': 'x/kzelkLxVE7fUibpVJ4gFn/8g4OeheoFYnzd8nwQSdry5oFcUA17p2DVo/HVu0zdXY+Cpdb98tWFbLQDQ+DqYrTGb4VuzQryeNUelmahuiJKxq4Cim13LtYNi8/ZvGOwFJEIbnvUWrrEQYjTXopYvDHTXZuDgegc7M1XGYzZ9WCOpDl/VljN/MTwhYGtLYgdSlEsvTkoi6bPw0v6xdtGe4OjaJmHPFzkd4+m7qlnvfM9pUmpYwugf7RNgZBis0jp4EGZpvRnn1bEWsuYYNmc+Y8/UI3iewBj7ZDHO7nF40=',
'encSecKey': '8b830008944ef7f41191e9f3c0efc6a327d407b77b5c0c403c0e62e3ef18685e53dba865cf38b120f89eb3fb20313f8722fa984eb2983888b891c05b74f29e6be7142d4ada2a000af421c24e09d809fecd648080515c767c00ca781a88bb3df506cf6c62663f1c5d9adebafa28774735bb874cb71f0108cfab26ad8a3ce6b4eb'
}
heades = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.42',
'cookie': '_ntes_nuid=b0f0d72129a0493bbc24517f9fabcf83; nts_mail_user=xieming436976@163.com:-1:1; WNMCID=qwviqz.1664113538433.01.0; WEVNSM=1.0.0; WM_TID=bcS%2FzjXwq2hBEVAEBRfQTip1qWM6OddA; NTES_P_UTID=wOn6feVPnZKXDFjWaks2Rcmi7ogqkeOd|1674225549; timing_user_id=time_9fqZvM9h3G; _ga=GA1.1.1673648894.1676436204; _clck=307tcm|1|f95|0; Qs_lvt_382223=1676436204%2C1676438752; Qs_pv_382223=2065062709232064800%2C578763537404371800; _ga_C6TGHFPQ1H=GS1.1.1676438752.2.0.1676438761.0.0.0; _ntes_nnid=b0f0d72129a0493bbc24517f9fabcf83,1678007997953; NMTID=00OcIcFLrurL2RIIEzCuKehQTaibSsAAAGGsRIRxQ; __snaker__id=X5AGPm1wbWktNYb7; gdxidpyhxdE=XUZomGgsp01vo8eMXOXIBMS3J%2FEIsb%2BM4Xuqm9r2bkVneUB21Nbtvuy18oeCR%2B60WRVb%2BUi%2BCNxoYe7SGEE0cuP8H%5CvroyUljwqU7Sny7tV%2FvRa86iJSAnPXuRGM%5CKxGR02%2Bj6j3K3aOIUABywZzBwYibBp7gajXgCln%2BMI809RNTskP%3A1678008905065; YD00000558929251%3AWM_NI=89%2Fsd6yHkQZUNmMUmp8rbHTDas8CO3x%2BN%2FiKsqAqnVP0srbKAfgyVTMwg5znpzVaFY1K4gXq1cyeC%2FshiRD8Cm2%2BcRmFnfj1RQlzf0Er66pgusr%2BjLF1kX0Ce8FTmTd2TFM%3D; YD00000558929251%3AWM_NIKE=9ca17ae2e6ffcda170e2e6ee9bcc43f8b2c0b5c54ab5ac8fa7c44b878a9f86d848a8ac88a6b3618ab0bab7c12af0fea7c3b92afce7e194e73ebb98a5b2d95f8eb383b6f07cfcaeaea9d750a3adf8a4ce39bcf582d0ec41b1af8f92ed5e94f0bd93e14183baa99ad5608fa9a9d6f966b4a69a82c553f395fc88db7bf3bdb786c225b1b8a7b3c73481b3fecce25aaf9aa287e93b928fa49be53c87aefad7f36db7adbecce94886efa5b9b349a7e88ab5f060a8ee9ca7d037e2a3; YD00000558929251%3AWM_TID=lVs%2FtX%2FSf2hBABBFVFKVacsHRhxc5qFQ; __bid_n=186b119b8b88afe0e94207; FPTOKEN=W+nhD6vaW22Y7GArPQq12tN1OxG1ONQJ6q1qNXDtGG11k9iF2i2lFMERBz4r8iRWj4h6iU0ZE1VdF9PZkLHRiSB0rM8nsbANDrEva4SrFDsoma52CTK3bai+AFKO6D1ke+olSPWD9mgDvnQLZETRKGMW/YfwIe520wMNNjZGYvjtTULo67BnGJWYcCV2O0Yb8sUZyAMby63g4eNjiNhArAjSWxw/+CYcHPmxxK+3FULNQlgI7UfDYSzq0niogGL2gDrhSx+zM4NGEnK2b51lNS2JSnZJWadBu3sVaZC+b9MkuwnufjaopavJIIFs5KGHlS3vOQe+2v/vbqGOfhbzMP+Ygro5zjgil1K+9CWbgnQuEUJdHOxPDCmK/aqlg7ceYQJm5fWW0cO3agAPXJ4dcQ==|I3pVGxSrxTf6FnZi3pKyZI5WvdohHGACTNTuSJPhUzM=|10|2e7019bd7a6cbab4e8d260fbb0b1df6b; vinfo_n_f_l_n3=dbd673b3dad9ad35.1.1.1670250136138.1670250148750.1678009286626; JSESSIONID-WYYY=T4z28fKYbv2ZT%5Co0Ap1N%2FV0FFPZZr3FUUuIVNv%2B0o1AAEIgj%5CyPbe9hTJuYBFrUs4xmPQEQYe7Otid24MyBWO1tE5Ac6MdN7Dn2WKOn%5CeGxgUWpvXWl6U7Glo4svgBghIWwUdWJZuw2VnbnCmwziX7f10%2FyGIvFoUdFlTo0Z%2FDjYmEhM%3A1678178467610; _iuqxldmzr_=33; WM_NI=MefrO%2BLXp67fAUjKr%2Brq33kK3%2BiehwrqI29iyt7vFbU2A4B2XqZW9hAXCXltwN2orvPuk%2F%2FMVgUIRxVGUT1StwShp4dCGH8aNqVXDpUnm7K6oTckc674IOr0o6auhXwvMW0%3D; WM_NIKE=9ca17ae2e6ffcda170e2e6eea6b57da2bef9aafc4a9b8e8ab2c55a838e8e87d5418eaeaba6b57ba9b5a5b5b52af0fea7c3b92a8fbbaa93ce219088c0d7b66e838ba6acf121b2affdd4ea41f1f5a786eb7db2af87d3bc63bbacf997c56a97ee8fd5c13a9caf96b8bc6483888db9ef80b592fe90f17e94aba5d0ae4796b99baad17496999bb5b459b8a99d89f340a89d89a9bb6b8eaf9ab9c77c97b2a3d8ca3ead8cad8ce23ef5ec87b0f13cadeaaf96eb54b5aa83b8b337e2a3; playerid=38430251',
'accept-encoding': ' gzip, deflate, br',
'accept-language': ' zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'origin': ' https://music.163.com',
'referer': 'https://music.163.com/search/'
}
requ = requests.post(url, data=fromData).json()['result']['songs']
for i in requ:
name = i['name']
music_id = i['id']
url = 'http://music.163.com/song/media/outer/url?id={}.mp3'.format(music_id)
mp3 = requests.get(url).content
with open("music/"+name+".mp3", "wb") as f:
f.write(mp3)
print(name, "下载成功")
f.close()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。