let axios = require('axios') const cheerio = require('cheerio'); const qs = require('querystring'); let getcontlist = async (text) => { let $ = cheerio.load(text) let list = [] // console.log($(".row .m-0").eq(1).html()) $ = cheerio.load($(".row .m-0").eq(1).html()) // console.log($("li").eq(0).html()) $("div").each((index,ele)=>{ let j = cheerio.load($(ele).html(),{decodeEntities: false}) // console.log(unescape(j('.tt').eq(0).html())) let obj = {}; obj.update = "暂无数据" obj.name = j(".comicbook-index a").eq(0).attr('title') obj.date = "暂无数据" obj.url = j(".comicbook-index a").eq(0).attr('href') // console.log(obj) list.push(obj) }) return list } let gethtml = async (name, page) => { name = qs.escape(name) let url = `https://www.manhuadb.com/search?q=${name}&p=${page}` // console.log(url) let text = "" await axios.get(url).then((a) => { // console.log(a.data) // res(a.text) text = a.data }) let list = [] try { list = await getcontlist(text) } catch (error) { // console.log(error) } list = {name:"漫画DB",list} return list } let getlist = (name) => { return new Promise(async (res,rej)=>{ try { let html; html = await gethtml(name, 1) console.log(JSON.stringify(html)) res(html); } catch (error) { rej([]) } }) } // getlist("青春") module.exports = getlist