How to Scrape and Export Your Sina Weibo Favorites with Python

This tutorial explains how to use Python to log into Sina Weibo, download your favorite posts, comments, images, and video links, save the raw HTML, and outlines the steps and script needed to automate the extraction and later processing of the collected data.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Scrape and Export Your Sina Weibo Favorites with Python

Using Python to Export Sina Weibo Favorites

The author discovered over 2,000 collected Weibo items spanning 104 pages and wanted to automate their extraction into a document.

Goal

Weibo post text and comments

Images

Video links

Approach

1. Simulate login to Sina Weibo and save the authentication cookie.

2. Use the cookie to request the favorites page URLs.

3. Iterate from the first page to the last, performing two actions for each page:

Download the raw HTML (requires internet to view dynamic content).

Parse and store the needed Weibo content for later processing.

Future processing will use lxml with XPath to convert the saved HTML into a document, including images and video links.

Implementation Details

The login simulation follows the method described at http://www.douban.com/note/201767245/, which the author copied directly.

Steps

Open your Weibo account, go to the “Favorites” section (e.g., http://weibo.com/fav?leftnav=1&wvr=3.6&page=1) and note the URL prefix.

Edit the script with your username, password, and the URL prefix.

Run the script: python weibo_collect.py The script produces a tmpcontent file containing all raw Weibo information, which can later be parsed into the desired format.

Sample output screenshots are shown below:

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.

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