How to Scrape WeChat Moments with Python and Scrapy: Step‑by‑Step Guide
Learn how to export WeChat Moments using a third‑party service, set up a Scrapy project in Python, analyze the dynamic JSON responses, and write a crawler to extract timeline data, complete with screenshots and command‑line instructions for a fully functional scraper.
Getting the WeChat Moments Data
To scrape WeChat Moments, first use the third‑party service "出书啦" which can export Moments and generate a WeChat book. Follow the public account, click Create Book → WeChat Book , add the service as a friend via the QR code, and wait for the book generation notification.
Ensure your Moments are set to Public . Then open the provided external link, scan the QR code to authorize login, and you will reach the WeChat book web page.
Creating the Scrapy Project
Install Scrapy, then open a command line in your chosen folder and run: scrapy startproject weixin_moment Enter the project directory: cd weixin_moment Create a spider for the WeChat book domain:
scrapy genspider moment chushu.laThe generated folder structure will look like the following:
Analyzing the Webpage
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 status 200 with JSON data.
When you click a month in the navigation pane, the page loads the corresponding Moments via a POST request. The request payload changes for each month, indicating dynamic loading.
The server response contains the Moments data under the paras/data node, which can be parsed from JSON.
With the request pattern and JSON structure identified, you can now write a Scrapy spider to send the appropriate POST requests, parse the paras/data field, and store the extracted Moments data for further analysis.
Stay tuned for the next article where the full crawling code will be presented.
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.
