const urlencode = require('urlencode-gb2312-ignore'); const cheerio = require('cheerio') let axios = require('axios') var iconv = require('iconv-lite') let mainurl = "http://www.pufei.cc" let gethtml = (name) => { return new Promise(async (res, rej) => { name = urlencode(name,"gb2312") let seach = `orderby=1&myorder=1&tbname=mh&tempid=3&show=title%2Cplayer%2Cplayadmin%2Cbieming%2Cpinyin&keyboard=${name}&Submit=%CB%D1%CB%F7%C2%FE%BB%AD` axios.post(mainurl + "/e/search/index.php",seach,{ headers:{ "Content-Type": "application/x-www-form-urlencoded" }, responseType: "arraybuffer" }).then((r)=>{ // console.log(r.data) // res(r.data) r.data = iconv.decode(r.data,"gb2312") res(r.data) }) }) } let get = (name) => { return new Promise(async (res, rej) => { try { let html; await gethtml(name).then((res) => { html = res }) // console.log(html) let $ = cheerio.load(html) let list = [] await $("#dmList ul li").each((index, ele) => { // console.log(index,123) let item = cheerio.load($(ele).html(), { decodeEntities: false }) let name = item("dl dt a").html() let date = item("dl dd p").eq(0).html() let url = mainurl + item("dl dt a").attr("href") let update = item("dl dd p").eq(1).html().replace("", "").replace('', "").replace('
', "").replace("", "") date = date.replace("", "").replace('', "").replace('', "").replace("", "") // console.log({ // date, // name, // url, // update // }) let l = { date, name, url, update } list.push(l) }) list = { name: "扑飞漫画", list } console.log(list) res(list); } catch (error) { rej([]) } }) } module.exports = get