let axios = require('axios') const cheerio = require('cheerio'); const qs = require('querystring'); let getcontlist = async (text) => { let $ = cheerio.load(text) let list = [] $ = cheerio.load($(".am-avg-sm-3.am-thumbnails.list").eq(0).html()) // console.log($("li").eq(0).html()) $("li").each((index,ele)=>{ let j = cheerio.load($(ele).html(),{decodeEntities: false}) // console.log(unescape(j('.tt').eq(0).html())) let obj = {}; obj.update = j('.tip').eq(0).text() obj.name = j("a").eq(0).attr('title') obj.date = '未获取' obj.url = 'https://www.tohomh123.com' + j(".am-thumbnail 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.tohomh123.com/action/Search?keyword=${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, 1) console.log(JSON.stringify(html)) res(html); } catch (error) { rej([]) } }) } // getlist("我") module.exports = getlist