本帖最后由 Mr.Lih 于 2020-7-17 12:56 编辑
git码云地址 https://gitee.com/lihann/zhuazhua
源码:
[JavaScript] 纯文本查看 复制代码 const path = require('path');
const express = require('express');
const app = express()
const got = require('got');
app.use(express.json());
app.use(express.urlencoded({
extended: false
}));
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
app.use('/', (req, res) => {
const query = req.query
const url = query.url
const reg = query.reg
let data = [],
arr = [];
let reg1 = new RegExp(reg, "gm");
_get(url, reg1).then(e=>{
console.log(e);
if(!reg){
res.json({
data: e
})
return
}
e.replace(reg1, (...g) => {
const l = g.length - 3;
for (let i = 1; i <= l; i++) {
data.push(g[i])
if (i % l == 0) {
arr.push(data)
data = []
}
}
})
res.json({
data: arr
})
})
})
app.listen(3000, () => {
console.log("run 3000");
})
async function _get(url, reg1) {
const response = await got(url);
const str = response.body;
return str
}
新手一个 正在学习 希望大佬指出意见 |