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
| const EpubPress = require('epub-press-js'); const Thenjs = require('thenjs'); const cheerio = require('cheerio'); const supertest = require('supertest'); const _ = require('lodash');
let url = 'https://wangdoc.com/es6/'; let baseUrl = 'https://wangdoc.com/es6/'; const request = supertest(url);
Thenjs(cont => { request.get('').end(cont); }).then((cont, result) => { content = result.text; let $ = cheerio.load(content); let urlList = $('.panel-menu .panel-block aside .menu-list li a').toArray(); if (_.isEmpty(urlList)) { return cont('not get url list'); } let list = []; for (let urlEle of urlList) { let href = $(urlEle).attr('href'); href = href.substring(2); list.push(baseUrl + href); } console.log(list); cont(null, list); }).then((cont, list) => { const ebook = new EpubPress({ title: 'ECMAScript 6 - ruanyifeng', description: 'ECMAScript 6 ', urls: list }); ebook.publish().then(() => { return ebook.download('epub'); }).then(() => { cont(null, null) }).catch((error) => { cont(`Error: ${error}`); }); }).fin((cont, err, arg) => { console.log(err, arg); });
|