first commit

This commit is contained in:
编码猿
2024-09-27 01:21:21 +08:00
commit 20bc3c1b13
8 changed files with 367 additions and 0 deletions

43
index.js Normal file
View File

@@ -0,0 +1,43 @@
const axios = require("axios");
const router = require("./run");
const config = {
BaseUrl: 'https://mbizhi.cheetahfun.com/sj',
list: {
search(keyword = "jk", page = 1) {
return `${config.BaseUrl}/search.html?search=${keyword}&page=${page}`
}
}
}
/**
* 闲着蛋疼使用原生nodejs模仿 express 自己实现了 express 的路由
* 已实现 get post 方法支持,和 参数解析 req.query.xxreq.body.xx
*/
// http://127.0.0.1:3000/search?keyword=jk&page=1
router.get("/search",async (req,res) => {
res.setHeader('Content-Type','application/json; charset=UTF-8');
let { keyword, page } = req.query
let result = await get(config.list.search(keyword,page));
res.json(result)
})
// router.get("/test",async (req,res) => {
// res.setHeader('Content-Type','application/json; charset=UTF-8');
// res.json(req.query)
// })
// router.post("/test",async (req,res) => {
// res.setHeader('Content-Type','application/json; charset=UTF-8');
// res.json(req.body)
// })
const get = async (url) => {
let res = await axios.get(url);
// 通过分析 元气桌面 网站源码发现当前页面的json接口数据是页面中的script代码运行后的函数返回值
// 所以先 match 提取 window.__NUXT__ 和 )) 中间的 核心js代码因为nodejs没有window所以先将代
// 码 中 window 替换为 config然后 eval 执行对方网站的 代码,拿到方法返回值,也就是我们的 【接口数据】
return eval(res.data.match(/window.__NUXT__([\s\S]*?)\)\);/)[0].replace("window", "config"))
}