core/bin/reptile/manhuadb_com/section.js

42 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-01-18 16:58:13 +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())
$(".fade").each((index,ele)=>{
// $(ele)
// console.log($(ele).html())
let obj = {}
let j = cheerio.load($(ele).html(),{decodeEntities: false})
obj.title = j(".comic_version_title").eq(0).html()
// console.log(obj.title)
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(JSON.stringify(list))
return list
}
let gethtml = async (url)=>{
let text;
let baseurl = "https://www.manhuadb.com"
await axios.get(baseurl + url).then((res)=>{
text = res.data
})
// console.log(text)
let list = await getsection(text)
// console.log(JSON.stringify(list))
return list
}
// gethtml('/manhua/9008')
module.exports = gethtml