How to Scrape and Visualize Your WeChat Friends’ Locations with Python
This tutorial shows how to use Python's itchat library to extract your WeChat contacts' province and city information, analyze the distribution, and create visual maps, providing step‑by‑step guidance and sample screenshots for each stage.
Using the itchat library, you can programmatically access WeChat friends' basic profile data, including province and city. After installing itchat, run the script to generate a QR code, scan it with your phone, authorize the login, and load the contact list.
Once logged in, the script prints each friend's province information. The output can be saved to a text file for further analysis.
The console also displays red messages prompting you to scan the QR code, confirm authorization, and load the address book—these messages are normal and can be ignored.
After saving the printed data, you can see that most friends are located in China, with Liaoning, Guangdong, and Hunan provinces having the highest counts. A simple province‑wise chart reveals the distribution, while a map visualization highlights the regions with deeper colors.
Next, the script can be extended to fetch each friend's city. The resulting city list shows that Dalian, Guangzhou, Shenzhen, Hengyang, and Changsha are the most common locations among the contacts.
Saving the city data to a text file makes it easy to review the distribution and optionally create a geographic heat map for further insight.
By aggregating the city statistics, you can generate a map visualization to better understand the geographic spread of your WeChat contacts.
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.
