使用cheerio解析html
cnpm i cheerio axios -S
const koa = require("koa");
const app = new koa();
const Router = require("koa-router");
const router = new Router();
const axios = require("axios");
const cheerio = require("cheerio");
const url = "https://movie.douban.com/top250"
router.get("/douban",async ctx=>{
var html = await axios.get(url);
const $ = cheerio.load(html.data,{
decodeEntities:false //解码设置为false,中文不会乱码
});
var title = $("#content h1").html();
console.log(title)
ctx.body = title;
})
app.use(router.routes());
app.listen(8080)
/*
1.axios抓取豆瓣
2.cheerio解析页面
3.返回数据给前端
*/
//http://www.kuwo.cn/playlists
# 抓取酷我音乐 [{imgUrl:"xxx",name:"xxxx",playCount:xxx}]
接口文档
2-1 列表页
//locahost?start=0 默认地址 默认获取25条,想去获取下一个只用更改start值就可以了
//locahost?start=25
2-2 详情页的数据
/subject/:id
前后端接口联调
2-3 搜索页的数据
/search?keyword=value
http://www.kuwo.cn/playlists
抓取酷我搜索页