Created
March 27, 2019 01:41
-
-
Save yuanliwei/d25b7d2bb45372ef459f1340ce1ae398 to your computer and use it in GitHub Desktop.
获取小说名列表.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```javascript | |
var request = require('request') | |
var cheerio = require('cheerio') | |
async function get(page) { | |
return new Promise((resolve) => { | |
request.get(`https://www.80txt.com/sort3/${page}.html`, { | |
encoding: 'utf-8', | |
gzip: true | |
}, (err, resp, body) => { | |
let $ = cheerio.load(body) | |
let titles = $('div.title_box>div.book_bg>a') | |
let results = [] | |
titles.each((index, ele) => { | |
let title = $(ele).text() | |
title = title.split('TXT')[0].trim() | |
console.log(title); | |
results.push(title) | |
}); | |
resolve(results) | |
}) | |
}) | |
} | |
async function start() { | |
let fs = require('fs') | |
for (let i = 1; i < 333; i++) { | |
let results = await get(i) | |
fs.appendFileSync('books2.txt', results.join('\n'), 'utf-8') | |
} | |
} | |
start() | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment