core/bin/reptile/gufengmh8/section.js

39 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-12-17 20:55:50 +08:00
let axios = require('axios')
const cheerio = require('cheerio');
let getsection = async (text)=>{
let $ = cheerio.load(text)
let list = [];
// console.log($(".comic-chapters ").eq(0).html())
$(".comic-chapters").each((index,ele)=>{
// $(ele)
// console.log($(ele).html())
let obj = {}
let j = cheerio.load($(ele).html(),{decodeEntities: false})
obj.title = j(".pull-left").eq(0).html().replace('<span>','').replace('</span>','')
obj.list = []
j('li').each(function (index,ele){
let con = {}
con.url = j(this).find("a").eq(0).attr('href')
con.title = j(this).find("a").eq(0).html().replace('<span>','').replace('</span>','').replace(/\s+/g,"").replace('\\n','')
obj.list.push(con)
})
// console.log(obj)
list.push(obj)
})
// console.log(list)
return list
}
let gethtml = async (url)=>{
let text;
await axios.get(url).then((res)=>{
text = res.data
})
let list = await getsection(text)
// console.log(JSON.stringify(list))
return list
}
// gethtml('https://www.gufengmh8.com/manhua/touxingjiuyuetian/')
module.exports = gethtml