Skip to content

Commit

Permalink
modify to adapt github's new html
Browse files Browse the repository at this point in the history
  • Loading branch information
oGsLP committed May 31, 2019
1 parent 646e432 commit 8eae6fc
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/crawler/followCrawler.js
Expand Up @@ -44,7 +44,7 @@ module.exports = function(username) {

function crawlFollow(array, data) {
let $ = cheerio.load(data.toString());
$(".col-9 >div")
$(".col-lg-9 >div")
.filter(".position-relative")
.children()
.each((i, el) => {
Expand Down
2 changes: 1 addition & 1 deletion lib/crawler/reposCrawler.js
Expand Up @@ -10,7 +10,7 @@ module.exports = function(username) {
.then(response => {
let html = response.data.toString(); // 获取网页内容
const $ = cheerio.load(html); // 传入页面内容
$("#user-repositories-list li >.col-9").each(function() {
$("#user-repositories-list li >.col-lg-9").each(function() {
let repo = {};
repo.repoName = $(this)
.find("h3 >a")
Expand Down
8 changes: 5 additions & 3 deletions lib/crawler/userCrawler.js
Expand Up @@ -10,8 +10,8 @@ module.exports = function(username) {
let html = response.data.toString();
const $ = cheerio.load(html);
// Profile
let $profile = $(".h-card >div");
let $status = $($profile).filter(".user-status-container");
let $profile = $(".h-card >div").filter(".clearfix");
let $status = $($profile).find(".user-status-container");
let [stat_emoji, stat_desc] = [
$($status)
.find("g-emoji")
Expand All @@ -24,7 +24,9 @@ module.exports = function(username) {
.text()
.trim()
];
stat_emoji = stat_emoji.substr(0, stat_emoji.length / 2);
let $names = $($profile)
.find(".vcard-names-container")
.filter(".vcard-names-container")
.find("h1")
.children();
Expand All @@ -37,7 +39,7 @@ module.exports = function(username) {
.trim()
];

let $infos = $($profile).filter(".js-profile-editable-area");
let $infos = $($profile).find(".js-profile-editable-area");
let description = $($infos)
.find(".user-profile-bio>div")
.text()
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "git-info-crawler",
"version": "0.0.2",
"version": "0.0.3",
"description": "Crawl info from one git account",
"homepage": "",
"author": {
Expand Down
10 changes: 5 additions & 5 deletions test.js
Expand Up @@ -15,8 +15,8 @@
// const crawler = require("./../index");
// crawler.crawlRepos("oGsLP");

// const userCrawler = require("./lib/crawler/userCrawler");
// userCrawler("NJUSSJ").then(data => console.log(data));
const userCrawler = require("./lib/crawler/userCrawler");
userCrawler("NJUSSJ").then(data => console.log(data));
//
// const emojiCrawler = require("./lib/crawler/emojiCrawler");
//
Expand All @@ -26,6 +26,6 @@
// const dbUtil = require("./lib/util/MongoDBUtil");
// dbUtil.init();

const crawlFollow = require("./lib/crawler/followCrawler");
const printFollow = require("./lib/printer/followPrinter");
crawlFollow("oGsLP").then(res => printFollow(res));
// const crawlFollow = require("./lib/crawler/followCrawler");
// const printFollow = require("./lib/printer/followPrinter");
// crawlFollow("oGsLP").then(res => printFollow(res));
6 changes: 3 additions & 3 deletions test/crawler/reposCrawler.test.js
Expand Up @@ -9,10 +9,10 @@ describe("#reposCrawler", () => {
return crawlRepos("oGsLP").then(data => {
assert.strictEqual(data.username, "oGsLP");
assert.deepStrictEqual(data.repos.pop(), {
repoName: "HotelSystem",
desc: "软工第二次大作业:酒店管理系统",
repoName: "Software-Engineering-Team-Work2",
desc: "",
lang: "Java",
updated: "Nov 20, 2016"
updated: "Dec 21, 2017"
});
});
}, 10000);
Expand Down

0 comments on commit 8eae6fc

Please sign in to comment.