-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (30 loc) · 1.08 KB
/
index.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
const express = require('express')
const utility = require('utility')
const superagent = require('superagent')
const cheesuperagent = require('superagent-charset')
const cheerio = require('cheerio')
const app = express()
const targetUrl = 'http://m.zgmht.com/company-26.html'
app.get('/', (req, res) => {
superagent.get(targetUrl)
.charset('gbk')
.end((err, sres) => {
if (err) {
return next(err)
}
const $ = cheerio.load(sres.text, {
decodeEntities: false
})
let str = ''
$('#moreList li').each(function (idx, element) {
const $tit1 = $('#moreList li .tit1').eq(idx);
const $contact_person = $('#moreList li .contact_person').eq(idx);
const $tel = $('#moreList li .tel').eq(idx);
str += `${idx + 1}. ${$tit1.text()} - ${$contact_person.text()} - ${$tel.text()}<br/>`
})
res.send(str)
})
})
app.listen(7777, () => {
console.log('app is listening at port 7777')
})