完成
This commit is contained in:
parent
77061d8417
commit
c5207b7758
6
app.js
6
app.js
@ -3,6 +3,12 @@ const requter = require("./bin/router.js");
|
|||||||
dbs = require("./bin/mongodb.js")('mongodb://localhost:27017/Cartoon-And-Fiction',"Cartoon-And-Fiction")
|
dbs = require("./bin/mongodb.js")('mongodb://localhost:27017/Cartoon-And-Fiction',"Cartoon-And-Fiction")
|
||||||
// console.log(requter)
|
// console.log(requter)
|
||||||
// import requter from "./bin/router"
|
// import requter from "./bin/router"
|
||||||
|
let reptile = require("./bin/reptile/binimport")
|
||||||
|
reptilelist = [];
|
||||||
|
reptile().then((res)=>{
|
||||||
|
// console.log(res)
|
||||||
|
reptilelist = res;
|
||||||
|
})
|
||||||
const app = new Koa();
|
const app = new Koa();
|
||||||
app.use(async (ctx,next)=>{
|
app.use(async (ctx,next)=>{
|
||||||
// await next();
|
// await next();
|
||||||
|
@ -1,18 +1,20 @@
|
|||||||
let fs = require("fs")
|
let fs = require("fs")
|
||||||
let getreptilelist =(dirlist)=>{
|
let getreptilelist =(dirlist)=>{
|
||||||
new Promise((res,err)=>{
|
return new Promise((res,err)=>{
|
||||||
console.log(dirlist)
|
let reptilelist = [];
|
||||||
|
// console.log(dirlist)
|
||||||
for(let i in dirlist){
|
for(let i in dirlist){
|
||||||
let reptile = require(__dirname + "/" + dirlist[i] +"/config.js" )
|
let reptile = require(__dirname + "/" + dirlist[i] +"/config.js" )
|
||||||
console.log(reptile)
|
// console.log(reptile)
|
||||||
reptilelist.push(reptile)
|
reptilelist.push(reptile)
|
||||||
}
|
}
|
||||||
|
res(reptilelist)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
getlist =()=>{
|
getlist =()=>{
|
||||||
new Promise((r,e)=>{
|
return new Promise((r,e)=>{
|
||||||
fs.readdir(__dirname, (err, res) => {
|
fs.readdir(__dirname, (err, res) => {
|
||||||
for (let i in res) {
|
for (let i in res) {
|
||||||
if (res[i] == "binimport.js") {
|
if (res[i] == "binimport.js") {
|
||||||
@ -28,7 +30,7 @@ getlist =()=>{
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = getlist()
|
module.exports = getlist
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ let gethtml = async (name, page) => {
|
|||||||
let getlist = async (name) => {
|
let getlist = async (name) => {
|
||||||
let html;
|
let html;
|
||||||
html = await gethtml(name, 1)
|
html = await gethtml(name, 1)
|
||||||
console.log(JSON.stringify(html))
|
// console.log(JSON.stringify(html))
|
||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
// getlist("偷星九月天")
|
// getlist("偷星九月天")
|
||||||
|
@ -2,12 +2,14 @@ const cheerio = require('cheerio');
|
|||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
let getscript = async (url) => {
|
let getscript = async (url) => {
|
||||||
let text;
|
let text;
|
||||||
|
url = "https://www.gufengmh8.com" + url
|
||||||
await axios.get(url).then((res)=>{
|
await axios.get(url).then((res)=>{
|
||||||
// text = res.text
|
// text = res.text
|
||||||
// console.log(res.data)
|
// console.log(res.data)
|
||||||
text = res.data
|
text = res.data
|
||||||
})
|
})
|
||||||
let $ = cheerio.load(text);
|
let $ = cheerio.load(text);
|
||||||
|
let list;
|
||||||
$('script').each((index, ele) => {
|
$('script').each((index, ele) => {
|
||||||
// console.log(ele)
|
// console.log(ele)
|
||||||
let text = $(ele).html()
|
let text = $(ele).html()
|
||||||
@ -23,10 +25,13 @@ let getscript = async (url) => {
|
|||||||
// prevChapterData 上一页信息
|
// prevChapterData 上一页信息
|
||||||
// nextChapterData 下一页信息
|
// nextChapterData 下一页信息
|
||||||
// 页面地址为 基础url + 页信息.id
|
// 页面地址为 基础url + 页信息.id
|
||||||
console.log({ imghost, chapterPath, chapterImages, pageTitle, pageUrl, prevChapterData, nextChapterData, pageImage })
|
// console.log({ imghost, chapterPath, chapterImages, pageTitle, pageUrl, prevChapterData, nextChapterData, pageImage })
|
||||||
return { imghost, chapterPath, chapterImages, pageTitle, pageUrl, prevChapterData, nextChapterData, pageImage }
|
list = { imghost, chapterPath, chapterImages, pageTitle, pageUrl, prevChapterData, nextChapterData, pageImage }
|
||||||
|
// console.log(list)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
return list;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// getscript('')
|
// getscript('')
|
||||||
|
@ -1,42 +1,29 @@
|
|||||||
let getlist = async (ctx,next)=>{
|
|
||||||
await dbs.find('list').then((res)=>{
|
|
||||||
data = [];
|
|
||||||
for(let i in res.data){
|
|
||||||
data.push({
|
|
||||||
id:res.data[i].num_key,
|
|
||||||
type:res.data[i].type,
|
|
||||||
name:res.data[i].name
|
|
||||||
})
|
|
||||||
}
|
|
||||||
ctx.body = JSON.stringify({code:0,data})
|
|
||||||
})
|
|
||||||
// next()
|
|
||||||
}
|
|
||||||
//添加需要爬取的项目 name url type 0小说 1漫画
|
|
||||||
let addproject = async (ctx,next)=>{
|
|
||||||
if(ctx.query.name == undefined || ctx.query.url == undefined || ctx.query.type ==undefined){
|
|
||||||
ctx.body = "{code:1,msg:参数不能为空}"
|
|
||||||
}else{
|
|
||||||
await dbs.add('list',{name:ctx.query.name,url:ctx.query.url,type:ctx.query.type}).then((res)=>{
|
|
||||||
ctx.body = JSON.stringify(res)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
// next()
|
|
||||||
}
|
|
||||||
let rmproject = async (ctx,next) =>{
|
|
||||||
if(ctx.query.id == undefined){
|
|
||||||
ctx.body = "{code:1,msg:参数不能为空}"
|
|
||||||
}else{
|
|
||||||
await dbs.remove('list',{'num_key':ctx.query.id}).then((res)=>{
|
|
||||||
ctx.body="{code:1,msg:删除成功}"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let findlist = async (ctx,next)=>{
|
|
||||||
|
|
||||||
|
let findlist = async (ctx,next)=>{
|
||||||
|
let list = []
|
||||||
|
for(let i in reptilelist){
|
||||||
|
let a = await reptilelist[i].find(ctx.query.name)
|
||||||
|
list.push({name:reptilelist[i].name,list: [...a]})
|
||||||
|
}
|
||||||
|
ctx.body = JSON.stringify(list)
|
||||||
|
}
|
||||||
|
let section = async(ctx,next)=>{
|
||||||
|
for(let i in reptilelist){
|
||||||
|
if(ctx.query.name == reptilelist[i].name){
|
||||||
|
ctx.body = await reptilelist[i].section(ctx.query.url)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let picture = async(ctx,next)=>{
|
||||||
|
for(let i in reptilelist){
|
||||||
|
if(ctx.query.name == reptilelist[i].name){
|
||||||
|
// console.log(await reptilelist[i].imglist(ctx.query.url))
|
||||||
|
ctx.body = await reptilelist[i].imglist(ctx.query.url)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
module.exports = {
|
module.exports = {
|
||||||
'GET /getlist':getlist,
|
'GET /find':findlist,
|
||||||
'GET /addproject':addproject,
|
'GET /section':section,
|
||||||
'GET /rmproject':rmproject
|
'GET /picture':picture
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user