2020-01-02 21:58:17 +08:00
|
|
|
let axios = require('axios')
|
|
|
|
const cheerio = require('cheerio');
|
2020-01-03 14:29:01 +08:00
|
|
|
let iconv = require('iconv-lite');
|
|
|
|
let getsection = async (text) => {
|
|
|
|
var text = iconv.decode(text, 'gbk');
|
|
|
|
let $ = cheerio.load(text, { decodeEntities: false })
|
|
|
|
let list = []
|
|
|
|
$("#play_0 ul li").each((index, ele) => {
|
|
|
|
let item = cheerio.load($(ele).html(), { decodeEntities: false })
|
|
|
|
let url = item("a").attr("href")
|
|
|
|
let title = item("a").html()
|
|
|
|
// console.log(title)
|
|
|
|
list.push({url,title})
|
2020-01-02 21:58:17 +08:00
|
|
|
})
|
2020-01-03 14:29:01 +08:00
|
|
|
list = list.reverse()
|
2020-01-02 21:58:17 +08:00
|
|
|
// console.log(list)
|
2020-01-03 15:15:48 +08:00
|
|
|
list = {
|
|
|
|
title:"列表",
|
|
|
|
list:list
|
|
|
|
}
|
2020-01-02 21:58:17 +08:00
|
|
|
return list
|
|
|
|
}
|
|
|
|
|
2020-01-03 14:29:01 +08:00
|
|
|
let gethtml = async (url) => {
|
2020-01-02 21:58:17 +08:00
|
|
|
let text;
|
2020-01-03 14:29:01 +08:00
|
|
|
await axios({url,responseType: 'arraybuffer'}).then((res) => {
|
|
|
|
text = res.data
|
|
|
|
})
|
|
|
|
// console.log(text)
|
2020-01-02 21:58:17 +08:00
|
|
|
let list = await getsection(text)
|
2020-01-03 14:29:01 +08:00
|
|
|
// list = [{
|
|
|
|
// title:"漫画列表",
|
|
|
|
// list
|
|
|
|
// }]
|
|
|
|
// console.log(list)
|
2020-01-02 21:58:17 +08:00
|
|
|
// console.log(JSON.stringify(list))
|
|
|
|
return list
|
|
|
|
}
|
|
|
|
|
2020-01-03 14:29:01 +08:00
|
|
|
// gethtml('http://www.taduo.net/manhua/984/')
|
2020-01-02 21:58:17 +08:00
|
|
|
module.exports = gethtml
|