当前位置:   article > 正文

python爬取网易云音乐热评_网易云热评爬取

网易云热评爬取

由于网易云音乐热评特别不错,所以前段时间无聊就看了一下怎么爬他们的热评
,附上代码
这是直接爬出来的所有信息,需要在进行数据清洗下
不懂的可以私信我

import requests

cookies = {
    '_ntes_nuid': '132b56eb04cd7ae3dc141a67f1e00b92',
    '__gads': 'ID=edd475e49c259564:T=1522070635:S=ALNI_MaL6zNCOchTwNrS8aso4KJa96dHsw',
    'vjuids': '-202d8c038.162627acbc3.0.0c44fd974cd69',
    '_iuqxldmzr_': '32',
    '__utmz': '94650624.1537866836.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)',
    'WM_TID': 'S4BoTLNXpXBu1XuKXWJGvK2VNSl8A1R2',
    'mail_psc_fingerprint': '4a2ba8794d7a7cb253130b93cf150f04',
    'usertrack': 'ezq0o1vGzRQe23jDAzXKAg==',
    '_ga': 'GA1.2.1206578097.1539755287',
    'UM_distinctid': '1669aca0685ab-0d8c2646d156b1-5e4b2519-100200-1669aca0687451',
    'vjlast': '1522070637.1544581017.11',
    '__utma': '94650624.1971910903.1537866836.1543304403.1547020521.5',
    '_ntes_nnid': '132b56eb04cd7ae3dc141a67f1e00b92,1551923908660',
    'vinfo_n_f_l_n3': 'ed239199997e7529.1.17.1522070637531.1551150620657.1552439807970',
    '__f_': '1552527380802',
    'JSESSIONID-WYYY': 'VzxRm974Y8WbPeeFTyi%2BR9C769wQ1DF7hvjo2HOqEaYkajfA94%5CNme%2BBHQKfsmGq%2BTZYMus4Xgb%2B76sMsgYwudT%5CI1Hh6%2BAK2vx%2Fi4gsdSadfFT9%2F7ant5ST507rZVCaUpAjobt0UhvhngPgZ%2FJdxt%5CvCOXYGrdf9ixCsf%2BHgSeeTbxT%3A1553739054373',
    'WM_NI': 'JiBtIXn2eLKlhVwpn8xGT5hRgUqgTMx2%2FEfUXF0TUNwuzRjBZ8lysYoCPgJOgFFBrUJKAncSFlRqyx7Br1S6LwQT2gA0MeujdELLRIjJe42aHjtsBTQo3MV3DTHR260oR3M%3D',
    'WM_NIKE': '9ca17ae2e6ffcda170e2e6eea6c8499aaead95d673a1928ea7c54b829e8aafb86db28f8c92ec6983abadb5ca2af0fea7c3b92a8ab78e95cc54aeeeabadca68ac8ab991ed34bc999cd6eb5aa58bbf88d747bceee1a6e55f9c9a00b5d846b5abb6b3e94a9ae8a49af253ad9da088c945a59a8aa3f15f8a958f8fe25986b49e92fc74f59ebed2d23e90a99fb5b16d83f08386f862a89b84add143aa96abd5b16b8cb6bc94c16093b1fdaed539888c88b3b13ef4b19ed4d037e2a3',
    'MUSIC_U': 'd6bf02383c0a0234b8da0b7d717df069eb5f65aef8526abe35411b24a595d461fd2f81d778ffe31c3fa6925a46b62d12586a15998e43a379b6d53907a0dbb4064eb75c1ad5e4f24fde39c620ce8469a8',
    '__remember_me': 'true',
    '__csrf': '99b47f93e046944078bfca72a1619ef7',
}

headers = {
    'Origin': 'https://music.163.com',
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36',
    'Content-Type': 'application/x-www-form-urlencoded',
    'Accept': '*/*',
    'Referer': 'https://music.163.com/song?id=1346104327',
    'Connection': 'keep-alive',
}

params = (
    ('csrf_token', '99b47f93e046944078bfca72a1619ef7'),
)

data = {
  'params': '/2b9rp81m0RdIyYib3JsCnFPg6yT77pPGhY03ke5khMgbbbTrCEJho/4YG9xXvuh7kM4/+HG/rVH9PlIZ3SwCdFReymdZ3tB8o0T+sxRHREnY6tv3WJDb7HuRMEiYC+a15k61alvkIIhyGuVDBLQNVuhfBrJ2Ee0r6eqCGmbhBtn6R12QW5gLlLC+gQjWcoC4jZdQ6ERN5w4QXpgj0eNKX7cu/ooU/mQyagF23Np6Z4=',
  'encSecKey': '5ff6ba868d77aaabdd2f4e27af30c00bc085757e830c96f5624cd4dc1212af0e48d36e437d4930c08fd9f80aece6772a1b09d4c8c1ac7a903c02d03a08c078f399b90a89dbed6a45980c970956d76df60b3234c9e90d03fd2ec17037afdcfe131e48c8f444a129e203635a51dfdc91047a584ecffb373d32ee633cb74efa42d3'
}

# response = requests.post('https://music.163.com/weapi/v1/resource/comments/R_SO_4_1346104327', headers=headers, params=params, cookies=cookies, data=data)
response = requests.post('https://music.163.com/weapi/v1/resource/comments/R_SO_4_1354459686', headers=headers, params=params, cookies=cookies, data=data)

#NB. Original query string below. It seems impossible to parse and
#reproduce query strings 100% accurately so the one below is given
#in case the reproduced version is not "correct".
# response = requests.post('https://music.163.com/weapi/v1/resource/comments/R_SO_4_1346104327?csrf_token=99b47f93e046944078bfca72a1619ef7', headers=headers, cookies=cookies, data=data)
# print(response.text)
count = response.json()
print(count['hotComments'])
# print(type(count['hotComments']))
# f = open('./HotComments3.txt', 'w', encoding='utf-8')
# for i in count['hotComments']:
#     f.write('用户: ' + i['user']['nickname'] + '\n')
#     f.write('点赞数: ' + str(i['likedCount']) + '\n')
#     f.write('评论: ' + i['content'] + '\n')
#     f.write('*****************************************')
# f.close()```

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/409117
推荐阅读
相关标签
  

闽ICP备14008679号