var detail = async ctx=>{ const cheerio = require("cheerio") const axios = require("axios") let {id} = ctx.request.params; let url =`https://movie.douban.com/subject/${id}` // console.log(id) var html =await axios.get(url); const $ = cheerio.load(html.data,{decodeEntities:false}) // console.log(html) let items=$("#wrapper").find("#content"); let arr=[]; let title = $("#content").find("span[property='v:itemreviewed']").html(); let year = $("#content").find(".year").html(); let plot = $("#content").find("#info>span:nth-child(8)").html(); let criminal = $("#content").find("#info>span:nth-child(9)").html(); let toronto = $("#content").find("#info>span:nth-child(16)").html();; let amer = "美国"; let pianchang = "片长:" let time = $("#content").find("span[property='v:runtime']").html(); let rating = $("#content").find(".rating_num").html(); let comment = $("#content").find(".rating_people").text().replace(/[^\d]/g,""); let jianjie = $("#content").find("span[property='v:summary']").html().replace(/[\n]/g,"").trim(); let yanyuan = $("#content").find(".celebrities-list li"); let play = []; arr.push({ title,year,plot,criminal,toronto,amer,pianchang,time,rating,comment,jianjie,play }) yanyuan.each((index,value)=>{ let ppic = $(value).find("a").attr("href"); let pname = $(value).find("a").attr("title"); let role = $(value).find("div .role").html(); play.push({ ppic,pname,role }) }) ctx.body = { result:arr }}module.exports = detail;
const koa = require("koa");const app = new koa;const router = require("koa-router")();const cors = require("koa2-cors");app.use(cors({origin:"*"}));router.get("/subject/:id",require("./try"))app.use(router.routes()).use(router.allowedMethods());app.listen(2000)