61 lines
1.6 KiB
JavaScript
61 lines
1.6 KiB
JavaScript
let axios = require('axios')
|
|
const cheerio = require('cheerio');
|
|
const qs = require('querystring');
|
|
let getcontlist = async (text) => {
|
|
let $ = cheerio.load(text)
|
|
let list = []
|
|
$ = cheerio.load($(".mh-list.col7").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('.chapter').eq(0).text()
|
|
obj.name = j(".mh-item a").eq(0).attr('title')
|
|
obj.date = '未获取'
|
|
obj.url = 'https://www.tohomh123.com' + j(".mh-item 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 |