How to Use Python to Scrape WeChat Friend Counts and Gender Distribution
This tutorial demonstrates how to employ Python's itchat library to log into WeChat, retrieve the total number of contacts, analyze gender distribution, and visualize the results, providing step‑by‑step code, screenshots, and tips for verifying the data against the official app.
Previously we showed how to use Python web crawlers to fetch WeChat Moments data and visualize it with word clouds. This article continues the series by focusing on extracting the total number of WeChat contacts and the gender distribution of those contacts.
The approach relies on the itchat library, which provides a convenient bridge to access friend information. After installing the library, running the script displays a QR code that must be scanned with the mobile WeChat client to authorize the session.
Once logged in, the script retrieves the friend list and prints the total count. In the author's own account the script reports 1,637 friends, matching the number shown in the WeChat “Contacts” tab.
To analyze gender distribution, the script can either define a custom function that extracts the gender field or directly use value_counts() on the gender series. The resulting counts are displayed as an image showing 884 male, 655 female, and about 100 unknown contacts.
The article includes screenshots of the QR code login, the total count output, and the gender distribution chart.
For further exploration, the author mentions upcoming tutorials on extracting friends' location data and visualizing it.
Reference: https://blog.csdn.net/zhanshirj/article/details/74166303
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.
