Skip to content

Instantly share code, notes, and snippets.

@yuanliwei
Created March 27, 2019 01:41
Show Gist options
  • Save yuanliwei/d25b7d2bb45372ef459f1340ce1ae398 to your computer and use it in GitHub Desktop.
Save yuanliwei/d25b7d2bb45372ef459f1340ce1ae398 to your computer and use it in GitHub Desktop.
获取小说名列表.js
```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