承接上篇流程設計,本文實戰分析知乎登錄接口、_xsrf Token 獲取、驗證碼處理,以及 Follower/Followee 列表 API 的參數構造與認證機制。
https://www.zhihu.com/signin,開啟 Network 面板。URL: https://www.zhihu.com/login/emailMethod: POSTForm Data: _xsrf=xxx&password=xxx&captcha=xxx&email=xxx{"r":1, "msg":"用戶不存在"}{"r":1, "msg":"密碼錯誤"}登錄頁面源碼中隱藏表單域:
<input type="hidden" name="_xsrf" value="xxxxxxxxxxxxxxxx">
每次登錄前需解析頁面獲取最新 _xsrf,或從 Cookie _xsrf 讀取。
用戶主頁:https://www.zhihu.com/people/{url_token}/followers
滾動觸發異步請求:
GET https://www.zhihu.com/api/v4/members/{url_token}/followers?
per_page=10&
include=data[*].employments,cover_url,answer_count,articles_count,follower_count,gender,is_followed,badge[?(type=best_answerer)].topics&
limit=10&
offset=30
關鍵參數:
include:指定返回字段,支援 GraphQL 風格選擇器。limit/offset:分頁控制。paging.next(下一頁 URL)與 data[](用戶列表)。直接攜帶 Cookie 請求 API 會返回 {"message":"身份未經過驗證","code":100}。
原因:請求頭多了 x-zse-83 等簽名頭,需從用戶主頁 Cookie 中提取 d_c0 等關鍵字段構造合法簽名,或使用 Selenium/Playwright 模擬瀏覽器上下文。
下篇將實現完整登錄流程、驗證碼自動識別(OCR/打碼平台)、簽名算法還原與分散式爬蟲調度。
