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.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Scrape WeChat Moments with Python Scrapy: Step‑by‑Step Guide

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
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.

Data ExtractionWeChatWeb ScrapingScrapy
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.