Extract All @Mentions from a Zhihu Page with Simple Scripts
This guide shows how to collect every @mentioned user on a Zhihu question page by using a JavaScript bookmarklet or a Python script, explains the extraction process, provides the necessary code snippets, and discusses why following programmers on Zhihu may not be the most effective learning method.
Question: Which good programmers on Zhihu are worth following, especially those who write Python?
One answer provides a list of recommended Zhihu users (e.g., @钟莫兮, @珵cici, @隋柯西, …).
Another answer shares a JavaScript bookmarklet that extracts all @mentions on the current page:
javascript:var hashes = []; var list = $(".member_mention").get().filter(function (e) { var h = $(e).attr('data-hash'); if (hashes.indexOf(h) < 0) { hashes.push(h); return true } else { return false } }).sort(function (a, b) { var atext = $(a).text(), btext = $(b).text(); if (atext > btext) return 1; else if (atext < btext) return -1; return 0; }); var target = $($("#zh-question-detail")[0]).empty(); list.forEach(function (e) { target.append(e).append("<br />") }); void(0)It can be run by pasting the code into the browser address bar (or console) to list the mentioned users.
A Python script is also provided to fetch the same information:
#coding=utf-8
import re
import urllib
def getCoder(url):
page = urllib.urlopen(url)
html = page.read()
rule = r'<a data-hash=.*? href="(.*?)" class=.*?>@.*?</a>'
coderList = re.findall(rule, html)
for coderName in coderList:
print coderName
getCoder("http://www.zhihu.com/question/22576739")Additional advice explains why simply following programmers on Zhihu may not effectively improve coding skills, suggesting instead to browse “Python” topic highlights, read highly‑upvoted answers, and practice the learned methods.
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.
Huawei Cloud Developer Alliance
The Huawei Cloud Developer Alliance creates a tech sharing platform for developers and partners, gathering Huawei Cloud product knowledge, event updates, expert talks, and more. Together we continuously innovate to build the cloud foundation of an intelligent world.
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.
