Scrape NetEase Cloud Music Hot Comments and Visualize Them with Python

This tutorial shows how to capture hot comments from NetEase Cloud Music using Python web‑scraping techniques, handle the required encryption parameters, and then transform the data into bar charts and word clouds with pyecharts and WordCloud for clear visual insight.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Scrape NetEase Cloud Music Hot Comments and Visualize Them with Python

1. Data Acquisition

To create a word‑cloud and chart, we first need the comment data, which requires some web‑scraping tricks.

1.1 Packet analysis

Open the song page on NetEase Cloud Music, press F12, and locate the request that returns comments. The request URL contains the song ID and uses a POST method with two encrypted fields: params and encSecKey.

These fields differ for each song because they are generated by a specific encryption algorithm.

1.2 Handling encrypted parameters

The encrypted params and encSecKey can be copied directly from the browser for a quick solution; detailed decryption methods are discussed on Zhihu.

1.3 Fetching hot comments

import requests
import json

url = 'http://music.163.com/weapi/v1/resource/comments/R_SO_4_551816010?csrf_token=568cec564ccadb5f1b29311ece2288f1'

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

# Encrypted data copied from the browser
user_data = {
    'params': 'vRlMDmFsdQgApSPW3Fuh93jGTi/ZN2hZ2MhdqMB503TZaIWYWujKWM4hAJnKoPdV7vMXi5GZX6iOa1aljfQwxnKsNT+5/uJKuxosmdhdBQxvX/uwXSOVdT+0RFcnSPtv',
    'encSecKey': '46fddcef9ca665289ff5a8888aa2d3b0490e94ccffe48332eca2d2a775ee932624afea7e95f321d8565fd9101a8fbc5a9cadbe07daa61a27d18e4eb214ff83ad301255722b154f3c1dd1364570c60e3f003e15515de7c6ede0ca6ca255e8e39788c2f72877f64bc68d29fac51d33103c181cad6b0a297fe13cd55aa67333e3e5'
}

response = requests.post(url, headers=headers, data=user_data)
data = json.loads(response.text)
hotcomments = []
for hotcomment in data['hotComments']:
    item = {
        'nickname': hotcomment['user']['nickname'],
        'content': hotcomment['content'],
        'likedCount': hotcomment['likedCount']
    }
    hotcomments.append(item)

content_list = [c['content'] for c in hotcomments]
nickname = [c['nickname'] for c in hotcomments]
liked_count = [c['likedCount'] for c in hotcomments]

The JSON response contains fields such as user info, comment date, like count, and the array hotComments with the top 15 comments.

2. Data Visualization

After obtaining the comment data, we install the required packages: pyecharts for charts, matplotlib for plotting, and WordCloud for the word cloud. pip install pyecharts Example code to draw a bar chart of like counts:

from pyecharts import Bar
bar = Bar("Hot Comment Like Count")
bar.add("Likes", nickname, liked_count, is_stack=True, mark_line=["min", "max"], mark_point=["average"])
bar.render()

The comment with the highest likes (95,056) is:

@鱼大叔Uncle:后来的我,离开了他,永远的离开了他,十年的感情不过寥寥几句话。后来的我,嫁给了一个很普通的人,没有他的浪漫,却有不一样的温暖。

Most likes range between 20,000‑30,000, with a minimum around 7,000, matching the numbers shown on the website.

Finally, we generate a word cloud from all hot‑comment texts:

from wordcloud import WordCloud
import matplotlib.pyplot as plt
content_text = " ".join(content_list)
wordcloud = WordCloud(font_path=r"C:\simhei.ttf", max_words=200).generate(content_text)
plt.figure()
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
plt.show()

The word cloud reveals recurring phrases like “后来只有你我,再无我们”.

3. Conclusion

This guide demonstrates a complete workflow: capture encrypted API parameters, retrieve hot comments via POST, parse the JSON, and visualize the results with bar charts and word clouds, providing a clear picture of audience sentiment for the song.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Pyechartswordcloudweb-scrapingdata-visualizationnetease-musiccomments-analysis
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.