zoukankan      html  css  js  c++  java
  • 网易云音乐的案例

    # coding = utf-8
    from Crypto.Cipher import AES
    import base64
    import requests
    import json

    headers = {
    'Host': 'music.163.com',
    'Origin': 'http://music.163.com',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
    'Cookie': '_ntes_nuid=f06d3ad37351b5873976195a9494a02d; _ntes_nnid=f102fe8ae1e8dd9ed03607cdefb1c942,1497115499078; usertrack=ZUcIhlmSfomGqgIViqQQAg==; P_INFO="wg03156419@126.com|1502852871|0|unireg|00&99|null&null&null#bej&null#10#0#0|&0||wg03156419@126.com"; _ga=GA1.2.478581340.1502773419; __gads=ID=02cb5469ddd177c4:T=1506065729:S=ALNI_MZ9QlRybfcDfjZVRKwT8W_Bv1CftQ; vjuids=6c007fd66.15ea88cc3cc.0.8971b60c9fb4f; vjlast=1506066351.1506583363.13; vinfo_n_f_l_n3=a2092b13a348e589.1.1.1506066351102.1506066377628.1506583384074; _iuqxldmzr_=32; __utmc=94650624; __utmz=94650624.1521856821.3.2.utmcsr=baidu|utmccn=(organic)|utmcmd=organic; JSESSIONID-WYYY=u9SvNoV%2FXRomtTlZNB0ZIIe0VwF%2BD40Sx1NZU%5CGoiobfm6b%2FzCATtdRCD29qziIez%2FpTGGY%2Fa6ZegzTxo3app6l%2BiA6diHt%2FScw9vYSWb5VaA1YJW6FBujX3orZC6lgKZK9o21KKTrqfidGtXkHH9Mvav2U8EUfFHY%2F%2Bsw7wJ8OMcNCq%3A1522142142350; __utma=94650624.478581340.1502773419.1522129721.1522141162.7; __utmb=94650624.2.10.1522141162; playerid=67808580',
    'Referer': 'http://music.163.com/'
    }

    first_param ="{"ids":"[551866648]","br":'128000',"csrf_token":""}"
    second_param = "010001"
    third_param = "00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7"
    forth_param = "0CoJUm6Qyw8W8jud"



    def get_params():
    iv = "0102030405060708"
    first_key = forth_param
    second_key = 16 * 'F'
    # print(first_param, first_key, iv)
    h_encText = AES_encrypt(first_param, first_key, iv)
    # print(h_encText,second_key, iv)
    h_encText = AES_encrypt(h_encText.decode('utf8'), second_key, iv)
    return h_encText

    def get_encSecKey():
    encSecKey = "257348aecb5e556c066de214e531faadd1c55d814f9be95fd06d6bff9f4c7a41f831f6394d5a3fd2e3881736d94a02ca919d952872e7d0a50ebfa1769a7a62d512f5f1ca21aec60bc3819a9c3ffca5eca9a0dba6d6f7249b06f5965ecfff3695b54e1c28f3f624750ed39e7de08fc8493242e26dbc4484a01c76f739e135637c"
    return encSecKey


    def AES_encrypt(text, key, iv):
    pad = 16 - len(text) % 16
    print('++++++++++++++++++++++++++++++++++++++++++++',pad)
    text = text + pad * chr(pad)
    print('---------------------------------------------',chr(pad))
    encryptor = AES.new(key, AES.MODE_CBC, iv)
    encrypt_text = encryptor.encrypt(text)
    print(777777777777777777777777777777,encrypt_text)
    encrypt_text = base64.b64encode(encrypt_text)
    print(8888888888888888888888888888888, encrypt_text)
    return encrypt_text
    def get_json(url, params, encSecKey):
    data = {
    "params": params.decode('utf8'),
    "encSecKey": encSecKey,
    }
    print(1,params.decode('utf8'))
    print(2,encSecKey)

    print(data)
    response = requests.post(url, headers=headers, data=data)
    return response.content
    if __name__ == "__main__":
    url='http://music.163.com/weapi/song/enhance/player/url?csrf_token='
    params = get_params()
    encSecKey = get_encSecKey()
    json_text = get_json(url, params, encSecKey)
    print(json_text.decode('gb18030'))
    print(json.loads(json_text.decode('gb18030'))['data'][0]['url'])
    header={
    'Host': 'm10.music.126.net',
    'Referer': 'http://music.163.com/',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',

    }
    source = requests.get(json.loads(json_text.decode('gb18030'))['data'][0]['url'],headers=header).content
    mp3 = open('hello.mp3','wb')
    mp3.write(source)
    mp3.close()

    上面这部分是获取歌曲的

    下面是获取评论的

    # coding = utf-8
    from Crypto.Cipher import AES
    import base64
    import requests
    import json

    headers = {
    'Host': 'music.163.com',
    'Origin': 'http://music.163.com',
    'Referer': 'http://music.163.com/',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36',
    }

    # first_param = "{rid:"", offset:"0", total:"true", limit:"20", csrf_token:""}"
    first_param ='{"rid":"A_PL_0_2182683172","offset":"20","total":"false","limit":"20","csrf_token":""}'
    second_param = "010001"
    third_param = "00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7"
    forth_param = "0CoJUm6Qyw8W8jud"


    def get_params():
    iv = "0102030405060708"
    first_key = forth_param
    second_key = 16 * 'F'
    h_encText = AES_encrypt(first_param, first_key, iv)
    print(11111111111111111111111, h_encText)
    h_encText = AES_encrypt(h_encText.decode('utf8'), second_key, iv)
    return h_encText


    def get_encSecKey():
    encSecKey = "257348aecb5e556c066de214e531faadd1c55d814f9be95fd06d6bff9f4c7a41f831f6394d5a3fd2e3881736d94a02ca919d952872e7d0a50ebfa1769a7a62d512f5f1ca21aec60bc3819a9c3ffca5eca9a0dba6d6f7249b06f5965ecfff3695b54e1c28f3f624750ed39e7de08fc8493242e26dbc4484a01c76f739e135637c"
    return encSecKey

    def AES_encrypt(text, key, iv):

    pad = 16 - len(text) % 16
    text = text + pad * chr(pad)
    print(666666666666666666,text)
    encryptor = AES.new(key, AES.MODE_CBC, iv)

    encrypt_text = encryptor.encrypt(text)
    print(99999999999999999999999999999, encrypt_text)
    encrypt_text = base64.b64encode(encrypt_text)
    print(8888888888888888888888888888, encrypt_text)
    return encrypt_text


    b'ZGkUv/4Bip5NOMm3pW6VUoIXNy4pXGlPOKUqV7Fahvri9NioYA2LT4Jcy9xHaZ7K3aewf44rCANs+P8tR12XsAAA0HIH9y+079FIXIdGHc0zwz3wyOk5aYHry+kS1PbS'

    def get_json(url, params, encSecKey):
    data = {
    "params": params,
    "encSecKey": encSecKey
    }
    response = requests.post(url, headers=headers, data=data)
    return response.content


    if __name__ == "__main__":
    url = "http://music.163.com/weapi/v1/resource/comments/R_SO_4_30953009/?csrf_token="
    params = get_params();
    encSecKey = get_encSecKey();
    json_text = get_json(url, params, encSecKey)
    json_dict = json.loads(json_text)
    print(json_dict)
    print(json_dict['total'])
    for item in json_dict['comments']:
    print( item['content'])





  • 相关阅读:
    11g 配置 dgmgrl 以及报错 DataGuard ORA-00313,
    java三种匿名的方式开启线程
    java 四种方式实现字符流文件的拷贝对比
    java中过滤查询文件
    通过Java实现斗地主
    java中Map的entrySet 和keySet的使用
    python3列表推导式和生成器。
    python的特殊方法总结
    python3 定义向量运算
    python3模拟扑克牌
  • 原文地址:https://www.cnblogs.com/mypath/p/8984179.html
Copyright © 2011-2022 走看看