forked from Aaaaaaaty/blog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspiderSchool.js
76 lines (75 loc) · 1.85 KB
/
spiderSchool.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
var superagent = require('superagent')
var cheerio = require('cheerio')
var http = require('http')
var url = require('url');
var async = require('async')
var encoding = require('encoding')
const area = [
'北京',
'天津',
'河北',
'河南',
'山东',
'山西',
'陕西',
'内蒙古',
'辽宁',
'吉林',
'黑龙江',
'上海',
'江苏',
'安徽',
'江西',
'湖北',
'湖南',
'重庆',
'四川',
'贵州',
'云南',
'广东',
'广西',
'福建',
'甘肃',
'宁夏',
'新疆',
'西藏',
'海南',
'浙江',
'青海',
'香港',
'澳门',
]
var numMax = 0
const server = http.createServer((req, res) => {
var count = 0;
var fetchUrl = function (offset, callback) {
count++;
console.log('当前并发数:', count)
var baseUrl = 'https://data-gkcx.eol.cn/soudaxue/queryschool.html?messtype=jsonp&callback=jQuery183024315414059533924_1513933822848&province=&schooltype=&page=1&size=30&keyWord1=&schoolprop=&schoolflag=&schoolsort=&schoolid=&_=1513933823095'
http.get('baseUrl', (res) => {
var rowData = ''
res.on('data', (chunk) => { rawData += chunk; });
res.on('end', () => {
try {
const parsedData = JSON.parse(rawData);
console.log(parsedData);
} catch (e) {
console.error(e.message);
}
});
}).on('error', (e) => {
console.error(`错误: ${e.message}`);
});
};
var offsets = [];
for(var i = 1; i < 2; i++) {
offsets.push(i);
}
async.mapLimit(offsets, 5, function (offset, callback) {
fetchUrl(offset, callback);
}, function (err, result) {
// res.writeHead(200, { 'Content-Type': 'text/plain; charset=gb2312' });
console.log(result)
// res.end(JSON.stringify(result))
});
}).listen(9090)