Skip to content

Instantly share code, notes, and snippets.

@detailyang
Last active December 26, 2015 17:59
Show Gist options
  • Save detailyang/7191459 to your computer and use it in GitHub Desktop.
Save detailyang/7191459 to your computer and use it in GitHub Desktop.
zhihu.js
main();
function main() {
var users = ['guxizhao', 'zou-dao-kou', 'xiaodaoren', 'cai-tong', 'xu-xiang-nan', 'unogzx', 'shenbin', 'PeterDeng', 'namiheike', 'wu-si-yang-32', 'yskin', 'jixin'];
var results = new Array();
var usercursor = 0;
var search_result = '<div id="bg" style="width:100%;height:100%;top:0;left:0;position:absolute;background-color:rgba(0, 0, 0, 0.2);z-index:9999;"></div><div id="search-result" style="width: 480px;left:50%;top:20%;margin-left: -240px; position: fixed; background: white; z-index: 99999;"><div class="search-result-header" style="background-color: rgb(200, 200, 169); margin: 0px;"><h1 style="margin:0px;">loading</h1></div><div class="search-result-body" style="background-color: rgb(131, 175, 155); margin: 0px; overflow-y: auto; height: 400px;"></div></div><iframe class="spilder-frame" src="" style="display:none"></iframe>';
$("body").append(search_result);
next_user();
//finished loading the iframe
$(".spilder-frame").load( function() {load();});
function load() {
var contents= $(".spilder-frame").contents();
if (contents.find(".zu-button-more[aria-role]").length ) {
contents.find(".zu-button-more[aria-role]")[0].click();
var followees = contents.find(".zm-profile-section-list .zm-profile-section-item").each(
function() {
var user = new Object();
var i = $(this);
content = i.find(".zm-list-content-medium");
user.name = content.find("h2 a")[0].text;
user.followers = content.find(".details a")[0].text.split(' ')[0];
user.asks = content.find(".details a")[1].text.split(' ')[0];
user.answers = content.find(".details a")[2].text.split(' ')[0];
user.agrees = content.find(".details a")[3].text.split(' ')[0];
if (parseInt(user.answers) && ((parseInt(user.agrees) / (parseInt(user.answers))) >= 500)) {
results[user.name] = user;
}
}
);
show_result();
} else {
next_user();
}
setTimeout(load, 3000);
}
function next_user() {
if (usercursor <= users.length) {
$(".spilder-frame").attr("src", "/people/" + users[usercursor++] + "/followees");
} else {
$(".search-result-header h1").html("Complete!");
}
}
function show_result() {
var body = $(".search-result-body");
var table = '<table style=""><tr><td>用户名</td><td>粉丝</td><td>提问</td><td>回答</td><td>赞同</td></tr>';
var array_results = new Array();
for (var item in results) {
array_results.push(results[item]);
}
array_results = array_results.sort(function (a, b) {
return Number(b.agrees) - Number(a.agrees);
});
for (var item in array_results) {
table += '<tr><td>'+array_results[item].name+'</td><td>'+array_results[item].followers+'</td><td>'+array_results[item].asks+'</td><td>'+array_results[item].answers+'</td><td>'+array_results[item].agrees +'</td></tr>';
}
table += '</table>';
body.html(table);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment