How to Scrape WeChat Moments with Python Scrapy: Step‑by‑Step Guide
This tutorial walks you through obtaining WeChat Moments data via a third‑party export service, setting up a Scrapy project, analyzing the JSON responses, and implementing the spider code to extract and save posts and timestamps.
1. Obtain WeChat Moments Data Entry
Follow the public account "出书啦", click "创作书籍" → "微信书", add the provided QR‑code friend, and wait for the generated WeChat book link. Ensure your Moments are set to "全部开放" (public).
2. Create Scrapy Project
Install Scrapy, then run:
scrapy startproject weixin_moment
Enter the project directory and generate a spider:
scrapy genspider 'moment' 'chushu.la'
The resulting folder structure is shown in the accompanying screenshot.
3. Analyze Webpage Data
Open the WeChat book page in Chrome, press F12, go to the Network tab, and enable "Preserve log". The initial request is a GET returning JSON data. Navigating by month triggers POST requests with changing payload parameters, and the response JSON contains the Moments under the /data node.
4. Code Implementation
Modify items.py to define fields for the post content and its publish date.
Update the spider file moment.py :
Import the item class.
Implement start_requests to request the exported WeChat book URL.
Parse the navigation JSON in parse, handling byte‑to‑string conversion.
Construct POST parameters as strings (year, month, index) and include required headers such as Referer.
Define parse_moment to extract each Moment from the JSON and yield the populated item.
Enable the item pipeline in settings.py by uncommenting the relevant line.
Run the spider:
scrapy crawl moment -o moment.json
If the output file shows garbled characters, re‑run with UTF‑8 encoding:
scrapy crawl moment -o moment.json -s FEED_EXPORT_ENCODING=utf-8
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.
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.
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.
