Create Stunning Word Clouds from WeChat Moments with Python: Step‑by‑Step Guide
Learn how to extract WeChat Moments data using Python web scraping, process the Chinese text with jieba, generate and customize word clouds with the wordcloud library, and enhance visual appeal using WordArt, all illustrated with detailed code snippets and screenshots.
Previously we used a Python web crawler to collect data from WeChat Moments; this article shows how to visualize that data with word clouds.
First, install the required libraries wordcloud and jieba via pip install wordcloud jieba.
You also need a Chinese font such as simhei.ttf; download it from the internet.
Create a file analyse.py next to items.py and define an analyse_words function. Use jieba.cut to obtain word segmentation and load the JSON data from moment.json for processing.
Note: when opening moment.json, specify encoding='utf-8' to avoid GBK encoding errors.
Run the program; it generates keys.png in the items.py directory.
Open keys.png to view the basic word cloud.
The initial cloud is functional but visually unappealing; we improve it using the WordArt online tool.
For example, applying an animal-shaped template yields a more attractive result.
To avoid clutter, preprocess the JSON: extract all text into moment.txt.
Write code to segment the text; the implementation is shown below.
Running the script produces moment_outputs.txt, which clearly displays the segmentation results.
Next, write code to count word frequencies; the snippet is illustrated below.
After execution, a text file and an Excel sheet containing the frequency statistics are generated.
Import these keywords into WordArt to create visually appealing word clouds.
Adjust shape, font, layout, and colors to produce vibrant clouds, such as a dog-shaped word cloud.
Another example is a cloud-shaped word cloud that offers a visual feast.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Python Crawling & Data Mining
Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
