From 716090b6ef26aac2005b56b10d3be6dceecfe731 Mon Sep 17 00:00:00 2001 From: pplok <1162963624@qq.com> Date: Fri, 17 Jan 2020 15:33:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/reptile/177mh_net/find.js | 12 ++-- bin/reptile/gufengmh8/find.js | 13 ++-- .../pufei_net/{badconfig.js => config.js} | 0 bin/reptile/pufei_net/find.js | 5 ++ bin/reptile/taduo_net/find.js | 69 ++++++++++--------- controllers/main.js | 29 ++++---- 6 files changed, 75 insertions(+), 53 deletions(-) rename bin/reptile/pufei_net/{badconfig.js => config.js} (100%) diff --git a/bin/reptile/177mh_net/find.js b/bin/reptile/177mh_net/find.js index 52736d3..d381b14 100644 --- a/bin/reptile/177mh_net/find.js +++ b/bin/reptile/177mh_net/find.js @@ -52,10 +52,14 @@ let gethtml = async (name) => { let getlist = (name) => { return new Promise(async (res,rej)=>{ - let html; - html = await gethtml(name) - // console.log(JSON.stringify(html)) - res(html); + try { + let html; + html = await gethtml(name) + // console.log(JSON.stringify(html)) + res(html); + } catch (error) { + rej([]) + } }) } diff --git a/bin/reptile/gufengmh8/find.js b/bin/reptile/gufengmh8/find.js index f857459..81741f2 100644 --- a/bin/reptile/gufengmh8/find.js +++ b/bin/reptile/gufengmh8/find.js @@ -45,10 +45,15 @@ let gethtml = async (name, page) => { let getlist = (name) => { return new Promise(async (res,rej)=>{ - let html; - html = await gethtml(name, 1) - // console.log(JSON.stringify(html)) - res(html); + try { + let html; + html = await gethtml(name, 1) + // console.log(JSON.stringify(html)) + res(html); + } catch (error) { + rej([]) + } + }) } diff --git a/bin/reptile/pufei_net/badconfig.js b/bin/reptile/pufei_net/config.js similarity index 100% rename from bin/reptile/pufei_net/badconfig.js rename to bin/reptile/pufei_net/config.js diff --git a/bin/reptile/pufei_net/find.js b/bin/reptile/pufei_net/find.js index 38de638..c9af4e8 100644 --- a/bin/reptile/pufei_net/find.js +++ b/bin/reptile/pufei_net/find.js @@ -82,6 +82,7 @@ let gethtml = (name) => { let get = (name) => { return new Promise(async (res, rej) => { + try { let html; await gethtml(name).then((res) => { html = res @@ -115,6 +116,10 @@ let get = (name) => { list = { name: "扑飞漫画", list } res(list); + } catch (error) { + rej([]) + } + }) } diff --git a/bin/reptile/taduo_net/find.js b/bin/reptile/taduo_net/find.js index a734d6e..52ba3b7 100644 --- a/bin/reptile/taduo_net/find.js +++ b/bin/reptile/taduo_net/find.js @@ -74,38 +74,43 @@ let gethtml = (name) => { let get = (name) => { return new Promise(async (res,rej)=>{ - 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) => { - 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) - }) - // console.log(list) - list = {name:"塔多漫画",list} - - res(list); + + 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) => { + 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) + }) + // console.log(list) + list = {name:"塔多漫画",list} + + res(list); + } catch (error) { + rej([]) + } }) } diff --git a/controllers/main.js b/controllers/main.js index b17e036..f866b6a 100644 --- a/controllers/main.js +++ b/controllers/main.js @@ -28,25 +28,28 @@ let findlist = async (ctx, next) => { pro.push(reptilelist[i].find(ctx.query.name)) } - await Promise.all(pro).then((res) => { + await Promise.allSettled(pro).then((res) => { // console.log(res) for (let i in res) { - for (let j in res[i].list) { - let has = true - for (let k in list) { - if (list[k].name == res[i].list[j].name) { - if (list[k].list == undefined) { - list[k].list = [] + if(i.status == "fulfilled"){ + for (let j in res[i].value.list) { + let has = true + for (let k in list) { + if (list[k].name == res[i].value.list[j].name) { + if (list[k].list == undefined) { + list[k].list = [] + } + has = false + list[k].list.push({ name: res[i].value.name, url: res[i].value.list[j].url, date: res[i].value.list[j].date, update: res[i].value.list[j].update }) } - has = false - list[k].list.push({ name: res[i].name, url: res[i].list[j].url, date: res[i].list[j].date, update: res[i].list[j].update }) + + } + if (has) { + list.push({ name: res[i].value.list[j].name, list: [{ name: res[i].value.name, url: res[i].value.list[j].url, date: res[i].value.list[j].date, update: res[i].value.list[j].update }] }) } - - } - if (has) { - list.push({ name: res[i].list[j].name, list: [{ name: res[i].name, url: res[i].list[j].url, date: res[i].list[j].date, update: res[i].list[j].update }] }) } } + } })