Created
May 20, 2018 11:08
-
-
Save corvofeng/cdb3cc45df113721a8592bff60002156 to your computer and use it in GitHub Desktop.
姐姐托我给外甥女估分选个学校, 看到一个没排序的名单, 遂给其排序
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 基于网站 http://www.cunet.com.cn/gaozhao/HTML/239864.html | |
// 姐姐托我给外甥女估分选个学校, 看到了下面这个网址, 可是这里面的信息是没有排序的, 所以自己写了一个排序程序 | |
// 可以按照分数进行排序. | |
var wrap = document.getElementsByClassName('wrap_centerfont'); | |
var tbl = wrap[0].children[2]; | |
var all_tbs = tbl.tBodies[0].children | |
// | |
var all_school = []; | |
for(var i = 1; i < all_tbs.length; i++) { | |
let tmp = all_tbs[i]; | |
all_school.push({ | |
'name': tmp.children[1].innerText, | |
'score': tmp.children[4].innerText | |
}); | |
} | |
all_school.sort(function(x,y){ | |
return x.score < y.score? 1: -1; | |
}); | |
for(let school of all_school) { | |
console.log(school.name, school.score); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment