增加爬虫
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
export default {
|
export default {
|
||||||
port: 3030,
|
port: 3030,
|
||||||
|
proxyPort: '7890',
|
||||||
baseUrl: 'https://www.06se.com',
|
baseUrl: 'https://www.06se.com',
|
||||||
hot_tags: function () {
|
hot_tags: function () {
|
||||||
return `${this.baseUrl}/hot_tags`
|
return `${this.baseUrl}/hot_tags`
|
||||||
|
|||||||
40
newBackApi/package-lock.json
generated
40
newBackApi/package-lock.json
generated
@@ -12,6 +12,7 @@
|
|||||||
"axios": "^1.7.7",
|
"axios": "^1.7.7",
|
||||||
"cheerio": "^1.0.0-rc.12",
|
"cheerio": "^1.0.0-rc.12",
|
||||||
"express": "^4.21.1",
|
"express": "^4.21.1",
|
||||||
|
"https-proxy-agent": "^7.0.5",
|
||||||
"ip": "^2.0.1"
|
"ip": "^2.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -27,6 +28,17 @@
|
|||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/agent-base": {
|
||||||
|
"version": "7.1.1",
|
||||||
|
"resolved": "https://registry.npmmirror.com/agent-base/-/agent-base-7.1.1.tgz",
|
||||||
|
"integrity": "sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA==",
|
||||||
|
"dependencies": {
|
||||||
|
"debug": "^4.3.4"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 14"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/array-flatten": {
|
"node_modules/array-flatten": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmmirror.com/array-flatten/-/array-flatten-1.1.1.tgz",
|
"resolved": "https://registry.npmmirror.com/array-flatten/-/array-flatten-1.1.1.tgz",
|
||||||
@@ -237,6 +249,22 @@
|
|||||||
"url": "https://github.com/sponsors/fb55"
|
"url": "https://github.com/sponsors/fb55"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/debug": {
|
||||||
|
"version": "4.3.7",
|
||||||
|
"resolved": "https://registry.npmmirror.com/debug/-/debug-4.3.7.tgz",
|
||||||
|
"integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"ms": "^2.1.3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"supports-color": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/define-data-property": {
|
"node_modules/define-data-property": {
|
||||||
"version": "1.1.4",
|
"version": "1.1.4",
|
||||||
"resolved": "https://registry.npmmirror.com/define-data-property/-/define-data-property-1.1.4.tgz",
|
"resolved": "https://registry.npmmirror.com/define-data-property/-/define-data-property-1.1.4.tgz",
|
||||||
@@ -668,6 +696,18 @@
|
|||||||
"node": ">= 0.8"
|
"node": ">= 0.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/https-proxy-agent": {
|
||||||
|
"version": "7.0.5",
|
||||||
|
"resolved": "https://registry.npmmirror.com/https-proxy-agent/-/https-proxy-agent-7.0.5.tgz",
|
||||||
|
"integrity": "sha512-1e4Wqeblerz+tMKPIq2EMGiiWW1dIjZOksyHWSUm1rmuvw/how9hBHZ38lAGj5ID4Ik6EdkOw7NmWPy6LAwalw==",
|
||||||
|
"dependencies": {
|
||||||
|
"agent-base": "^7.0.2",
|
||||||
|
"debug": "4"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 14"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/iconv-lite": {
|
"node_modules/iconv-lite": {
|
||||||
"version": "0.4.24",
|
"version": "0.4.24",
|
||||||
"resolved": "https://registry.npmmirror.com/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
"resolved": "https://registry.npmmirror.com/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
"axios": "^1.7.7",
|
"axios": "^1.7.7",
|
||||||
"cheerio": "^1.0.0-rc.12",
|
"cheerio": "^1.0.0-rc.12",
|
||||||
"express": "^4.21.1",
|
"express": "^4.21.1",
|
||||||
|
"https-proxy-agent": "^7.0.5",
|
||||||
"ip": "^2.0.1"
|
"ip": "^2.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
import * as cheer from "cheerio";
|
import * as cheer from "cheerio";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import { HttpsProxyAgent } from "https-proxy-agent";
|
||||||
import Config from "../config/config.js";
|
import Config from "../config/config.js";
|
||||||
|
|
||||||
class utils {
|
class utils {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.ax = axios
|
this.ax = axios
|
||||||
|
// 让 ajax 请求 走flclash的翻墙代理
|
||||||
|
const httpsAgent = new HttpsProxyAgent(`http://127.0.0.1:${Config.proxyPort}`);
|
||||||
|
this.ax.defaults.httpsAgent = httpsAgent;
|
||||||
|
this.ax.defaults.proxy = false;
|
||||||
|
|
||||||
this.ResponseInterceptor()
|
this.ResponseInterceptor()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -17,7 +23,7 @@ class utils {
|
|||||||
return cheer.load(html)
|
return cheer.load(html)
|
||||||
}
|
}
|
||||||
|
|
||||||
split(str,index = 1) {
|
split(str, index = 1) {
|
||||||
return str.split(Config.baseUrl)[index]
|
return str.split(Config.baseUrl)[index]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +52,14 @@ class utils {
|
|||||||
this.ax.interceptors.response.use((response) => {
|
this.ax.interceptors.response.use((response) => {
|
||||||
return this.cheerio(response.data);
|
return this.cheerio(response.data);
|
||||||
}, (error) => {
|
}, (error) => {
|
||||||
console.log("请求错误...");
|
console.log(`
|
||||||
|
❌ 请求错误❕❕❕
|
||||||
|
1: 错误信息 ${error.message}
|
||||||
|
2: 原因:目标网站禁止国内大陆IP访问,爬虫会走系统代理进行请求访问
|
||||||
|
但检测到你未开启翻墙工具,请打开Clash或FlClash等代理工具,保证能正常访问 Google。
|
||||||
|
|
||||||
|
3: 自定义代理端口:修改代码'/config/config.js'中 proxyPort 实现自定义端口,端口从代理工具中查看
|
||||||
|
`);
|
||||||
return Promise.reject(error)
|
return Promise.reject(error)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user