core/bin/reptile/manhuadb_com/find.js

63 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

2020-01-18 16:58:13 +08:00
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}
2022-02-01 16:41:21 +08:00
console.log(list)
2020-01-18 16:58:13 +08:00
return list
}
let getlist = (name) => {
return new Promise(async (res,rej)=>{
try {
let html;
html = await gethtml(name, 1)
2022-02-01 16:41:21 +08:00
// console.log(JSON.stringify(html))
2020-01-18 16:58:13 +08:00
res(html);
} catch (error) {
rej([])
}
})
}
// getlist("青春")
2020-01-18 16:58:13 +08:00
module.exports = getlist