let axios = require('axios') const cheerio = require('cheerio'); const qs = require('querystring'); let getcontlist = async (text) => { let $ = cheerio.load(text) let list = [] // console.log($("ul").eq(1).html()) $ = cheerio.load($("ul").eq(1).html()) // console.log($("li").eq(0).html()) $("dl").each((index,ele)=>{ let j = cheerio.load($(ele).html(),{decodeEntities: false}) let name= j("dd h1 a").html().replace(//g,"").replace(/<\/em>/g,"") let url = j("dd h1 a").attr("href") let data = "暂无数据" let update = "暂无数据" let obj = {name,url,data,update}; // console.log(name,url) // console.log(unescape(j('.tt').eq(0).html())) // obj.update = j('.tt').eq(0).html() // obj.name = j(".ell a").eq(0).html() // obj.date = j(".updateon").eq(0).html().replace(/\s+/g,"").replace('1.0','') // obj.url = j(".cover").eq(0).attr('href') // // console.log(obj) list.push(obj) }) return list } let gethtml = async (name) => { name = qs.escape(name) let url = `https://so.177mh.net/k.php?k=${name}` // console.log(url) let text = "" await axios.get(url).then((a) => { // console.log(a.text) // res(a.text) text = a.data }) let list = [] try { list = await getcontlist(text) } catch (error) { // console.log(error) } list = {name:"新新漫画",list} return list } let getlist = (name) => { return new Promise(async (res,rej)=>{ try { let html; html = await gethtml(name) // console.log(JSON.stringify(html)) res(html); } catch (error) { rej([]) } }) } // getlist("隐之王") module.exports = getlist