core/bin/reptile/177mh_net/find.js
2020-01-17 15:33:56 +08:00

67 lines
1.9 KiB
JavaScript

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(/<em>/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('<em>1.0</em>','')
// 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