Skip to content

Commit 0e6d462

Browse files
committed
update: 导航爬虫
1 parent 527ec93 commit 0e6d462

File tree

12 files changed

+5228
-308
lines changed

12 files changed

+5228
-308
lines changed

images/navigate.png

5.39 KB
Loading

images/page_admin.png

46 KB
Loading

images/page_index.png

-77.7 KB
Loading

nav.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"scripts": {
66
"serve": "vue-cli-service serve",
77
"build": "vue-cli-service build",
8-
"lint": "vue-cli-service lint"
8+
"lint": "vue-cli-service lint",
9+
"pa": "node reptile/index.js"
910
},
1011
"dependencies": {
1112
"axios": "^0.18.0",

reptile/index.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const superagent = require('superagent');
2+
const request = require('request');
3+
const cheerio = require('cheerio');
4+
const fs = require('fs');
5+
6+
7+
/**
8+
* 请求函数
9+
*/
10+
function reptile(url, type) {
11+
request(url, function (error, res, body) {
12+
// console.error('error:', error); // Print the error if one occurred
13+
// console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
14+
// console.log('body:', body); // Print the HTML for the Google homepage.
15+
if (!error && res.statusCode == 200) {
16+
const $ = cheerio.load(body)
17+
const $cardBlock = $('.panel')
18+
let arr = []
19+
20+
for (let i = 0; i < $cardBlock.length; i++) {
21+
let obj = {}
22+
obj.classify = type + $('.panel-title.card').eq(i).text().trim()
23+
obj.sites = []
24+
const length = $('.panel').eq(1).find('.card-title').length
25+
for (let j = 0; j < length; j++) {
26+
let navItem = {}
27+
navItem.title = $('.card-title').eq(j).text().trim()
28+
navItem.href = $('.card .card-heading').eq(j).attr('title')
29+
navItem.desc = $('.card .card-body').eq(j).text().trim()
30+
navItem.logo = 'http://chuangzaoshi.com/' + $('.card-icon img').eq(j).attr('src')
31+
obj.sites.push(navItem)
32+
}
33+
arr.push(obj)
34+
}
35+
console.log(JSON.stringify(arr))
36+
}
37+
});
38+
}
39+
40+
// reptile('http://chuangzaoshi.com/index','[设计]') //设计
41+
// reptile('http://chuangzaoshi.com/code','[前端]') //前端
42+
// reptile('http://chuangzaoshi.com/product','[产品]') //产品
43+
reptile('http://chuangzaoshi.com/operate','[运营]') //运营

0 commit comments

Comments
 (0)