-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (49 loc) · 1.11 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const request = require('request');
const cheerio = require('cheerio');
const fs = require('fs');
const {
htmlDecode,
trim
} = require('./tool.js');
const sendMail = require('./mail.js');
let url = 'https://movie.douban.com/top250?start='
let obj = {
data: new Date,
url: url,
list: []
}
let index = 0;
let spider = () => {
if (index == 11) {
clearInterval(time)
fs.writeFile('./a.json', JSON.stringify(JSON.stringify(obj)), (err) => {
if (err) {
console.log(err);
}
})
} else {
let start = index * 25;
console.log(url + start);
request(url + start, (err, res, body) => {
index = index + 1;
if (err) {} else {
let $ = cheerio.load(body, {
decodeEntities: false
});
$('.grid_view .item').map((index, item) => {
movieObj = {
name: $(item).find('.title').html(),
star: $(item).find('.rating_num').html(),
quote: $(item).find('.inq').html(),
img: $(item).find('.pic img').attr('src'),
director: trim($(item).find('.bd p').text(), 'g'),
}
obj.list.push(movieObj);
});
}
})
}
}
let time = setInterval(() => {
spider()
}, 3000)