How to Simulate Weibo Login in Python: Step‑by‑Step Guide with Code

This article walks through the complete process of simulating a Weibo login using Python, covering pre‑login analysis, RSA password encryption, three implementation approaches, and full code examples to help developers avoid common pitfalls when building web‑scraping tools.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Simulate Weibo Login in Python: Step‑by‑Step Guide with Code

Recently I needed to scrape Weibo, so the first step was to simulate login, which can be tricky; I share my analysis process and code to help others avoid pitfalls.

First, I captured a normal login with Http Analyzer to see the requests and identified the pre‑login step that returns fields such as servertime, nonce and pubkey.

Pre‑login URL is http://login.sina.com.cn/sso/…; the su parameter is the base64‑encoded username. By inspecting the JavaScript file http://i.sso.sina.com.cn/js/ssologin.js we find the encoding functions.

The password is encrypted with RSA:

password = RSAKey.encrypt([me.servertime,me.nonce].join("\t") + "
" + password)

. Using this we must construct su, sp, servertime, nonce, rsakv, etc., then POST to

http://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.4.18)

.

I describe three login approaches: (a) directly translate the JavaScript encryption to Python, (b) use Selenium + PhantomJS/Firefox to automate the form, and (c) render the JavaScript with Pyexecjs (or PyV8) and execute it. I chose the third method because Python 3 lacks PyV8.

Using Pyexecjs with PhantomJS as the runtime, I executed the copied encryption function to obtain the encrypted password, then performed the POST request and followed the redirect URL containing the ticket to retrieve the final login information.

The complete code for all three methods is available on my GitHub repository “smart_login”.

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.

PythonSeleniumWeiboLogin SimulationPyexecjsRSA Encryption
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.