first commit
This commit is contained in:
8
.drone.yml
Normal file
8
.drone.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
kind: pipeline
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: test
|
||||
image: node
|
||||
commands:
|
||||
- npm run dev
|
||||
58
app.js
Normal file
58
app.js
Normal file
@@ -0,0 +1,58 @@
|
||||
import express from "express";
|
||||
import config from "./config/config.js";
|
||||
import { ipv6, ipv4 } from "./utils/ip.js";
|
||||
|
||||
import tagsRouter from "./router/tags.js";
|
||||
import infoRouter from "./router/info.js";
|
||||
import searchRouter from "./router/search.js";
|
||||
import homeRouter from "./router/home.js";
|
||||
import http from "http";
|
||||
|
||||
const app = express()
|
||||
|
||||
|
||||
|
||||
//解决跨域
|
||||
app.use((req, res, next) => {
|
||||
// 设置是否运行客户端设置 withCredentials
|
||||
// 即在不同域名下发出的请求也可以携带 cookie
|
||||
res.header("Access-Control-Allow-Credentials", true)
|
||||
// 第二个参数表示允许跨域的域名,* 代表所有域名
|
||||
res.header('Access-Control-Allow-Origin', '*')//配置80端口跨域
|
||||
res.header('Access-Control-Allow-Methods', 'GET, PUT, POST, OPTIONS') // 允许的 http 请求的方法
|
||||
// 允许前台获得的除 Cache-Control、Content-Language、Content-Type、Expires、Last-Modified、Pragma 这几张基本响应头之外的响应头
|
||||
res.header('Access-Control-Allow-Headers', '*')
|
||||
if (req.method == 'OPTIONS') {
|
||||
res.sendStatus(200)
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
})
|
||||
|
||||
app.use('/v1/api/tag', tagsRouter);
|
||||
app.use('/v1/api/info', infoRouter);
|
||||
app.use('/v1/api/search', searchRouter);
|
||||
app.use('/v1/api/home', homeRouter);
|
||||
|
||||
http.createServer(app).listen(config.port, "::",() => {
|
||||
console.log(`
|
||||
爬虫运行在下面网址:
|
||||
|
||||
1️⃣ 公网 IPV6: http://[${ipv6()}]:${config.port}
|
||||
2️⃣ 局域网 IPV4: http://${ipv4()}:${config.port}
|
||||
|
||||
`)
|
||||
})
|
||||
|
||||
// app.listen(config.port, () => {
|
||||
// console.log(`
|
||||
// 爬虫运行在下面网址:
|
||||
|
||||
// 1️⃣ 公网 IPV6: http://[${ipv6()}]:${config.port}
|
||||
// 2️⃣ 局域网 IPV4: http://${ipv4()}:${config.port}
|
||||
|
||||
// `)
|
||||
// })
|
||||
|
||||
|
||||
export default app
|
||||
8
config/config.js
Normal file
8
config/config.js
Normal file
@@ -0,0 +1,8 @@
|
||||
export default {
|
||||
port: 3030,
|
||||
proxyPort: '7890',
|
||||
baseUrl: 'https://www.06se.com',
|
||||
hot_tags: function () {
|
||||
return `${this.baseUrl}/hot_tags`
|
||||
}
|
||||
}
|
||||
1137
package-lock.json
generated
Normal file
1137
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
20
package.json
Normal file
20
package.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "newbackapi",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "node app.js"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"axios": "^1.7.7",
|
||||
"cheerio": "^1.0.0-rc.12",
|
||||
"express": "^4.21.1",
|
||||
"https-proxy-agent": "^7.0.5",
|
||||
"ip": "^2.0.1"
|
||||
}
|
||||
}
|
||||
75
router/home.js
Normal file
75
router/home.js
Normal file
@@ -0,0 +1,75 @@
|
||||
import express from "express";
|
||||
import Util from '../utils/index.js'
|
||||
import Config from '../config/config.js'
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
// 获取首页banner图
|
||||
// http://192.168.31.101:3030/v1/api/home/banner
|
||||
router.get('/banner', async (req, res) => {
|
||||
let $ = await Util.get(`${Config.baseUrl}/?orderby=rand`)
|
||||
let result = []
|
||||
|
||||
$(".new-swiper .swiper-wrapper .swiper-slide").each(function() {
|
||||
let src = $(this).find("span img").attr("src")
|
||||
if (src) {
|
||||
result.push({ src })
|
||||
}
|
||||
})
|
||||
|
||||
res.json({
|
||||
status: 200,
|
||||
copyright: `bmy ${new Date()}`,
|
||||
data: result
|
||||
})
|
||||
})
|
||||
|
||||
// 获取热门推荐的写真
|
||||
// http://192.168.31.101:3030/v1/api/home/hot
|
||||
router.get('/hot', async (req, res) => {
|
||||
let $ = await Util.get(`${Config.baseUrl}/?orderby=rand`)
|
||||
let result = []
|
||||
|
||||
$(".box-body .tab-content .posts-mini").each(function() {
|
||||
result.push({
|
||||
id: Util.split($(this).find(".item-thumbnail a").attr("href")).replace(/[^\d]/g, ""),
|
||||
thumbnail: $(this).find(".item-thumbnail a img").attr("data-src"),
|
||||
title: $(this).find(".item-heading a").text(),
|
||||
time: $(this).find(".item-meta .icon-circle").text(),
|
||||
view: $(this).find(".item-meta .meta-right .meta-view").text()
|
||||
})
|
||||
})
|
||||
|
||||
res.json({
|
||||
status: 200,
|
||||
copyright: `bmy ${new Date()}`,
|
||||
data: result
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
// 获取首页 默认的随机写真
|
||||
// http://192.168.31.101:3030/v1/api/home/list
|
||||
router.get('/list', async (req, res) => {
|
||||
let $ = await Util.get(`${Config.baseUrl}/?orderby=rand`)
|
||||
let result = []
|
||||
|
||||
$(".tab-content .posts-row .posts-item").each(function() {
|
||||
result.push({
|
||||
id: Util.split($(this).find(".item-thumbnail a").attr("href")).replace(/[^\d]/g, ""),
|
||||
thumbnail: $(this).find(".item-thumbnail a img").attr("data-src"),
|
||||
title: $(this).find(".item-heading a").text(),
|
||||
time: $(this).find(".item-meta .icon-circle").text(),
|
||||
view: $(this).find(".item-meta .meta-right .meta-view").text()
|
||||
})
|
||||
})
|
||||
|
||||
res.json({
|
||||
status: 200,
|
||||
copyright: `bmy ${new Date()}`,
|
||||
data: result
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
export default router
|
||||
42
router/info.js
Normal file
42
router/info.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import express from "express";
|
||||
import Util from '../utils/index.js'
|
||||
import Config from '../config/config.js'
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
// 进入详情的接口
|
||||
// http://192.168.31.101:3030/v1/api/info/list?id=6808
|
||||
router.get('/list', async (req, res) => {
|
||||
let { id } = req.query
|
||||
let $ = await Util.get(`${Config.baseUrl}/${id}.html`)
|
||||
let result = {
|
||||
title: $(".article .article-header .article-title a").text(),
|
||||
src_list: [],
|
||||
recommend: [],
|
||||
}
|
||||
|
||||
$(".article-content .wp-posts-content p img").map(function(i, el) {
|
||||
result.src_list.push($(el).attr("data-src"))
|
||||
})
|
||||
|
||||
$(".swiper-container .swiper-slide a").each(function(i, el) {
|
||||
result.recommend.push({
|
||||
id: Util.split($(this).attr("href")).replace(/[^\d]/g, ""),
|
||||
thumbnail: $(this).find("img").attr("data-src"),
|
||||
title: $(this).find(".text-ellipsis").text(),
|
||||
time: $(this).find(".px12 item").eq(0).text(),
|
||||
view: $(this).find(".px12 item").eq(1).text(),
|
||||
})
|
||||
})
|
||||
|
||||
res.json({
|
||||
status: 200,
|
||||
copyright: `bmy ${new Date()}`,
|
||||
data: result
|
||||
})
|
||||
|
||||
|
||||
|
||||
})
|
||||
|
||||
export default router
|
||||
70
router/search.js
Normal file
70
router/search.js
Normal file
@@ -0,0 +1,70 @@
|
||||
import express from "express";
|
||||
import Util from '../utils/index.js'
|
||||
import Config from '../config/config.js'
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
// 搜索页面的 热门关键词 & 推荐
|
||||
// http://192.168.31.101:3030/v1/api/search/hot
|
||||
router.get('/hot', async (req, res) => {
|
||||
let $ = await Util.get(`${Config.baseUrl}/wp-admin/admin-ajax.php?action=search_box`)
|
||||
let result = {
|
||||
hotKeyword: [],
|
||||
recommend: []
|
||||
}
|
||||
|
||||
$(".search-input .search-keywords").eq(0).find("div a").each(function() {
|
||||
result.hotKeyword.push($(this).text())
|
||||
})
|
||||
|
||||
$(".search-input .relates-thumb .swiper-slide a").each(function() {
|
||||
result.recommend.push({
|
||||
id: Util.split($(this).attr("href")).replace(/[^\d]/g, ""),
|
||||
thumbnail: $(this).find("img").attr("data-src"),
|
||||
title: $(this).find(".text-ellipsis").text(),
|
||||
time: $(this).find(".px12 item").eq(0).text(),
|
||||
view: $(this).find(".px12 item").eq(1).text(),
|
||||
})
|
||||
})
|
||||
|
||||
res.json({
|
||||
status: 200,
|
||||
copyright: `bmy ${new Date()}`,
|
||||
data: result
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
// 搜索接口
|
||||
// http://192.168.31.101:3030/v1/api/search/key?keyword=杨晨晨&page=1
|
||||
router.get('/key', async (req, res) => {
|
||||
let { keyword, page } = req.query
|
||||
page = page || 1
|
||||
|
||||
let $ = await Util.get(`${Config.baseUrl}/page/${page}?s=${encodeURI(keyword)}&type=post`)
|
||||
let result = {
|
||||
currentPage: page,
|
||||
totalPage: Number($(".pagenav .dots+a").text()),
|
||||
message: $(".search-content .badg .focus-color").text(),
|
||||
list: [],
|
||||
}
|
||||
|
||||
$(".search-content .posts-item").each(function() {
|
||||
result.list.push({
|
||||
id: Util.split($(this).find(".item-thumbnail a").attr("href")).replace(/[^\d]/g, ""),
|
||||
thumbnail: $(this).find(".item-thumbnail a img").attr("data-src"),
|
||||
title: $(this).find(".item-body .item-heading a").text(),
|
||||
time: $(this).find(".item-body .item-meta .icon-circle").text(),
|
||||
view: $(this).find(".item-body .item-meta .meta-right .meta-view").text()
|
||||
})
|
||||
})
|
||||
|
||||
res.json({
|
||||
status: 200,
|
||||
copyright: `bmy ${new Date()}`,
|
||||
data: result
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
export default router
|
||||
76
router/tags.js
Normal file
76
router/tags.js
Normal file
@@ -0,0 +1,76 @@
|
||||
import express from "express";
|
||||
import Util from '../utils/index.js'
|
||||
import Config from '../config/config.js'
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
// 获取 推荐标签
|
||||
// http://192.168.31.101:3030/v1/api/tag/recommend
|
||||
router.get('/recommend', async (req, res) => {
|
||||
res.json({
|
||||
status: 200,
|
||||
copyright: `bmy ${new Date()}`,
|
||||
data: [
|
||||
{ title: '秀人网', count: '9059', url: '/xiuren' },
|
||||
{ title: 'ROSI写真', count: '6580', url: '/domestic/rosi' },
|
||||
{ title: '蜜桃社', count: '122', url: '/domestic/miitao' },
|
||||
{ title: '尤物馆', count: '138', url: '/domestic/youwu' },
|
||||
]
|
||||
});
|
||||
})
|
||||
|
||||
// 获取 所有标签
|
||||
// http://192.168.31.101:3030/v1/api/tag/list
|
||||
router.get('/list', async (req, res) => {
|
||||
let $ = await Util.get(Config.hot_tags())
|
||||
let result = []
|
||||
$(".categorieslist ul li a").each(function (i) {
|
||||
result.push({
|
||||
title: $(this).find("h2").text(),
|
||||
count: $(this).find("small p").text().replace(/[^\d]/g, ""),
|
||||
url: Util.split($(this).attr("href")),
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
res.json({
|
||||
status: 200,
|
||||
copyright: `bmy ${new Date()}`,
|
||||
data: result
|
||||
});
|
||||
})
|
||||
|
||||
// 进入对应标签的列表页面
|
||||
// http://192.168.31.101:3030/v1/api/tag/info?url=/xiuren&page=1
|
||||
router.get('/info', async (req, res) => {
|
||||
let { url, page } = req.query
|
||||
page = page || 1
|
||||
|
||||
let $ = await Util.get(`${Config.baseUrl}${url}/page/${page}`)
|
||||
let result = {
|
||||
count: $(".content-layout .title-h-left .icon-spot").text().replace(/[^\d]/g, ""),
|
||||
introduce: $(".content-layout .muted-2-color").text(),
|
||||
totalPage: Number($(".pagenav .dots+a").text()),
|
||||
currentPage: page,
|
||||
list: []
|
||||
}
|
||||
|
||||
$(".content-layout .posts-row .posts-item").each(function (i) {
|
||||
result.list.push({
|
||||
id: Util.split($(this).find(".item-thumbnail a").attr("href")).replace(/[^\d]/g, ""),
|
||||
thumbnail: $(this).find(".item-thumbnail a img").attr("data-src"),
|
||||
title: $(this).find(".item-body .item-heading a").text(),
|
||||
time: $(this).find(".item-body .item-meta .icon-circle").text(),
|
||||
view: $(this).find(".item-body .item-meta .meta-right .meta-view").text()
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
res.json({
|
||||
status: 200,
|
||||
copyright: `bmy ${new Date()}`,
|
||||
data: result
|
||||
});
|
||||
})
|
||||
|
||||
export default router
|
||||
72
utils/index.js
Normal file
72
utils/index.js
Normal file
@@ -0,0 +1,72 @@
|
||||
import * as cheer from "cheerio";
|
||||
import axios from "axios";
|
||||
import { HttpsProxyAgent } from "https-proxy-agent";
|
||||
import Config from "../config/config.js";
|
||||
|
||||
class utils {
|
||||
constructor() {
|
||||
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()
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回 cheerio 数据结构
|
||||
* @param html
|
||||
* @returns {*}
|
||||
*/
|
||||
cheerio(html) {
|
||||
return cheer.load(html)
|
||||
}
|
||||
|
||||
split(str, index = 1) {
|
||||
return str.split(Config.baseUrl)[index]
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param url 请求的地址
|
||||
* @returns {Promise<AxiosResponse<any>>}
|
||||
*/
|
||||
async get(url) {
|
||||
return await this.ax.get(url, {
|
||||
headers: {
|
||||
'sec-ch-ua-mobile': '?1',
|
||||
'sec-fetch-site': 'same-origin',
|
||||
'upgrade-insecure-requests': '1',
|
||||
'priority': 'u=0, i',
|
||||
'sec-fetch-mode': 'navigate',
|
||||
'cookie': `_ga=GA1.1.1571194344.1732275775; _lscache_vary=0e8aace2958628a1edb01710bbabbcab; showed_system_notice=showed; PHPSESSID=5jmev023fsh6i76huat60njio3; _ga_ZT9Q6FCC5R=GS1.1.1732668048.9.1.1732668791.0.0.0`,
|
||||
'referer': 'https://www.06se.com/hot_tags',
|
||||
'user-agent': `Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1`
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 响应拦截器
|
||||
* @constructor
|
||||
*/
|
||||
async ResponseInterceptor() {
|
||||
this.ax.interceptors.response.use((response) => {
|
||||
return this.cheerio(response.data);
|
||||
}, (error) => {
|
||||
console.log(`
|
||||
❌ 请求错误❕❕❕
|
||||
1: 错误信息 ${error.message}
|
||||
2: 原因:目标网站禁止国内大陆IP访问,爬虫会走系统代理进行请求访问
|
||||
但检测到你未开启翻墙工具,请打开Clash或FlClash等代理工具,保证能正常访问 Google。
|
||||
|
||||
3: 自定义代理端口:修改代码'/config/config.js'中 proxyPort 实现自定义端口,端口从代理工具中查看
|
||||
`);
|
||||
return Promise.reject(error)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default new utils();
|
||||
12
utils/ip.js
Normal file
12
utils/ip.js
Normal file
@@ -0,0 +1,12 @@
|
||||
import ip from 'ip'
|
||||
|
||||
class IP {
|
||||
ipv6() {
|
||||
return ip.address('private','ipv6')
|
||||
}
|
||||
ipv4() {
|
||||
return ip.address('public','ipv4')
|
||||
}
|
||||
}
|
||||
|
||||
export const {ipv6,ipv4} = new IP()
|
||||
Reference in New Issue
Block a user