1. var detail = async ctx=>{
    2. const cheerio = require("cheerio")
    3. const axios = require("axios")
    4. let {id} = ctx.request.params;
    5. let url =`https://movie.douban.com/subject/${id}`
    6. // console.log(id)
    7. var html =await axios.get(url);
    8. const $ = cheerio.load(html.data,{decodeEntities:false})
    9. // console.log(html)
    10. let items=$("#wrapper").find("#content");
    11. let arr=[];
    12. let title = $("#content").find("span[property='v:itemreviewed']").html();
    13. let year = $("#content").find(".year").html();
    14. let plot = $("#content").find("#info>span:nth-child(8)").html();
    15. let criminal = $("#content").find("#info>span:nth-child(9)").html();
    16. let toronto = $("#content").find("#info>span:nth-child(16)").html();;
    17. let amer = "美国";
    18. let pianchang = "片长:"
    19. let time = $("#content").find("span[property='v:runtime']").html();
    20. let rating = $("#content").find(".rating_num").html();
    21. let comment = $("#content").find(".rating_people").text().replace(/[^\d]/g,"");
    22. let jianjie = $("#content").find("span[property='v:summary']").html().replace(/[\n]/g,"").trim();
    23. let yanyuan = $("#content").find(".celebrities-list li");
    24. let play = [];
    25. arr.push({
    26. title,year,plot,criminal,toronto,amer,pianchang,time,rating,comment,jianjie,play
    27. })
    28. yanyuan.each((index,value)=>{
    29. let ppic = $(value).find("a").attr("href");
    30. let pname = $(value).find("a").attr("title");
    31. let role = $(value).find("div .role").html();
    32. play.push({
    33. ppic,pname,role
    34. })
    35. })
    36. ctx.body = {
    37. result:arr
    38. }
    39. }
    40. module.exports = detail;
    1. const koa = require("koa");
    2. const app = new koa;
    3. const router = require("koa-router")();
    4. const cors = require("koa2-cors");
    5. app.use(cors({origin:"*"}));
    6. router.get("/subject/:id",require("./try"))
    7. app.use(router.routes()).use(router.allowedMethods());
    8. app.listen(2000)