core/bin/reptile/tohomh123_com/find.js

61 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-02-28 11:35:22 +08:00
let axios = require('axios')
const cheerio = require('cheerio');
const qs = require('querystring');
let getcontlist = async (text) => {
let $ = cheerio.load(text)
let list = []
2020-02-29 14:08:06 +08:00
$ = cheerio.load($(".am-avg-sm-3.am-thumbnails.list").eq(0).html())
2020-02-28 11:35:22 +08:00
// 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 = {};
2020-02-29 14:08:06 +08:00
obj.update = j('.tip').eq(0).text()
obj.name = j(".am-thumbnail a").eq(0).attr('title')
2020-02-28 11:35:22 +08:00
obj.date = '未获取'
2020-02-29 14:08:06 +08:00
obj.url = 'https://www.tohomh123.com' + j(".am-thumbnail a").eq(0).attr('href')
2020-02-28 11:35:22 +08:00
// 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)
2020-02-29 14:08:06 +08:00
console.log(JSON.stringify(html))
2020-02-28 11:35:22 +08:00
res(html);
} catch (error) {
rej([])
}
})
}
// getlist("我")
module.exports = getlist