解决了err之后不关闭浏览器的bug

This commit is contained in:
pplok 2020-01-26 17:44:13 +08:00
parent ea986575db
commit 9bfd44301f
8 changed files with 56 additions and 65 deletions

View File

@ -1,4 +0,0 @@
古风漫画网
www.gufengmh8.com
find.js 查找功能
section.js 获取章节列表

View File

@ -1,4 +0,0 @@
古风漫画网
www.gufengmh8.com
find.js 查找功能
section.js 获取章节列表

View File

@ -1,4 +0,0 @@
古风漫画网
www.gufengmh8.com
find.js 查找功能
section.js 获取章节列表

View File

@ -58,5 +58,5 @@ let getlist = (name) => {
})
}
getlist("青春")
// getlist("青春")
module.exports = getlist

View File

@ -1,4 +0,0 @@
古风漫画网
www.gufengmh8.com
find.js 查找功能
section.js 获取章节列表

View File

@ -9,8 +9,12 @@ let gethtml = (name) => {
}).then(async (browser) => {
const page = await browser.newPage();
await page.goto(mainurl);
try {
await page.goto(mainurl);
} catch (error) {
browser.close()
res([])
}
await page.click(".searchtext1")
await page.type(".searchtext1", name);
// const usernameValue = await page.$eval(".searchtext1", el => el.value);
@ -25,22 +29,22 @@ let gethtml = (name) => {
try {
await openpages[2].content().then((r) => {
// console.log(r)
if(r.indexOf("没有搜索到相关的内容") != -1 || r.indexOf("您当前的位置") != -1){
if (r.indexOf("没有搜索到相关的内容") != -1 || r.indexOf("您当前的位置") != -1) {
// console.log(r)
res(r)
clearInterval(set)
browser.close()
}else{
} else {
throw error;
}
})
} catch (error) {
num++
// console.log(num)
if(num > 10){
if (num > 10) {
res([])
clearInterval(set)
browser.close()
@ -82,44 +86,44 @@ let gethtml = (name) => {
let get = (name) => {
return new Promise(async (res, rej) => {
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) => {
// console.log(index,123)
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("<em>", "").replace('</em><span class="red">', "").replace('</span></p>', "").replace("</span>", "")
date = date.replace("<em>", "").replace('</em><span class="red">', "").replace('</span></p>', "").replace("</span>", "")
// console.log({
// date,
// name,
// url,
// update
// })
let l = {
date,
name,
url,
update
}
list.push(l)
})
// console.log(list)
list = { name: "扑飞漫画", 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) => {
// console.log(index,123)
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("<em>", "").replace('</em><span class="red">', "").replace('</span></p>', "").replace("</span>", "")
date = date.replace("<em>", "").replace('</em><span class="red">', "").replace('</span></p>', "").replace("</span>", "")
// 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([])
}
res(list);
} catch (error) {
rej([])
}
})
}

View File

@ -1,4 +0,0 @@
古风漫画网
www.gufengmh8.com
find.js 查找功能
section.js 获取章节列表

View File

@ -10,7 +10,14 @@ let gethtml = (name) => {
const page = await browser.newPage();
await page.goto(mainurl);
// await page.goto(mainurl);
try {
await page.goto(mainurl);
} catch (error) {
console.log("err")
browser.close()
res([])
}
await page.type(".searchtext1", name);
// const usernameValue = await page.$eval(".searchtext1", el => el.value);
await page.click("#btnSend1")