-
Notifications
You must be signed in to change notification settings - Fork 0
/
kindle.js
49 lines (40 loc) · 1.08 KB
/
kindle.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
var express=require('express');
var cheerio=require('cheerio');
var superagent=require('superagent');
var superagentcharset=require('superagent-charset');
superagentcharset(superagent);
var fs=require('fs');
var app=new express();
const baseUrl='http://mebook.cc/category/cxxs/page/';
app.get('/',function(req,res){
for(var i=1;i<=525;i++){
superagent.get(baseUrl+i).charset('utf-8').end(function(err,sres){
var items=[];
if(err){
console.log(err)
}
var $=cheerio.load(sres.text);
$("ul.list div.content h2 a").each(function(index,element){
var $element=$(element);
items.push({
title:$element.attr("title"),
href:$element.attr("href")
})
})
saveFile(items);
})
}
})
function saveFile(items){
for(var i=0;i<10;i++){
fs.appendFile('kindle.txt','书名:'+items[i].title+'\r\n'+'链接是:'+items[i].href+'\r\n',function(err){
if(!err){
}
});
}
}
app.listen(8080,function(err){
if(!err){
console.log("服务已启动")
}
})