-
Notifications
You must be signed in to change notification settings - Fork 9
/
spider-app.js
41 lines (28 loc) · 1.01 KB
/
spider-app.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
/**
* Created by ChenWeiYu
* Date : 2016/8/28
* Time : 15:07
*/
var spiderJSON = require('./models/spiderJSON');
var spiderHTML = require('./models/spiderHTML');
var express = require('express');
var app = express();
// 启动爬虫,在前端页面展示爬虫进度
app.get('/start', (req, res)=>{
res.writeHead(200, {'Content-Type': 'text/html;charset=utf-8' }); // text/html
// spiderHTML.start(req, res)
spiderJSON.start(req, res)
.then(() => {
res.write(`<br>职位列表爬取完毕<br>`)
spiderHTML.start(req, res)
})
process.on("uncaughtException", function (err) {
console.log('不知道什么错误发生了 : ', err);
// spiderHTML.start(req, res)
})
});
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log("爬虫应用实例,访问地址 http://%s:%s/start 启动爬虫并查看进度", host, port)
});