From 552bcb298291dcce290e05b8dbe386de45caedb6 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 2 Jul 2025 17:49:00 +0800 Subject: [PATCH] Wed Jul 2 17:49:00 CST 2025 inscode --- .inscode | 5 ++++- index.js | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++- package.json | 15 ++++++++----- 3 files changed, 74 insertions(+), 7 deletions(-) diff --git a/.inscode b/.inscode index e177731..b6e34e0 100644 --- a/.inscode +++ b/.inscode @@ -1,5 +1,8 @@ -run = "npm i && npm run dev" +run = "npm run dev" language = "node" +is_html = false +is_resident = true +is_gui = false [env] PATH = "/root/${PROJECT_DIR}/.config/npm/node_global/bin:/root/${PROJECT_DIR}/node_modules/.bin:${PATH}" diff --git a/index.js b/index.js index 2d7e683..9d37756 100644 --- a/index.js +++ b/index.js @@ -1 +1,60 @@ -console.log("欢迎来到 InsCode"); \ No newline at end of file +const express = require('express'); +const puppeteer = require('puppeteer-extra'); +const StealthPlugin = require('puppeteer-extra-plugin-stealth'); + +// 添加stealth插件 +puppeteer.use(StealthPlugin());peteer.use(StealthPlugin()); + +const app = express(); +const PORT = process.env.PORT || 3000; + +// 基本路由 +app.get('/', (req, res) => { + res.send(` +

欢迎来到 InsCode Node.js 示例

+

这是一个使用Express和Puppeteer的示例项目

+ + `); +}); + +// API路由 +app.get('/api/status', (req, res) => { + res.json({ + status: 'running', + version: '1.0.0', + timestamp: new Date().toISOString() + }); +}); + +// Puppeteer示例路由 +app.get('/scrape', async (req, res) => { + try { + const browser = await puppeteer.launch({ + headless: true, + args: ['--no-sandbox', '--disable-setuid-sandbox'] + }); + + const page = await browser.newPage(); + await page.goto('https://example.com'); + + const title = await page.title(); + await browser.close(); + + res.send(` +

Puppeteer抓取结果

+

Example.com的标题是: ${title}

+ 返回首页 + `); + } catch (error) { + res.status(500).send(`Error: ${error.message}`); + } +}); + +// 启动服务器 +app.listen(PORT, () => { + console.log(`Server running at http://localhost:${PORT}`); + console.log(`Puppeteer version: ${puppeteer.version}`); +}); \ No newline at end of file diff --git a/package.json b/package.json index 72caa17..2c1767f 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,23 @@ { "name": "nodejs", "version": "1.0.0", - "description": "", + "description": "Node.js project with Express and Puppeteer", "main": "index.js", "scripts": { "dev": "node index.js", + "start": "node index.js", "test": "echo \"Error: no test specified\" && exit 1" }, - "keywords": [], - "author": "", + "keywords": ["node", "express", "puppeteer"], + "author": "Your Name", "license": "ISC", "dependencies": { - "@types/node": "^18.0.6", - "node-fetch": "^3.2.6" + "@types/node": "^20.11.19", + "node-fetch": "^3.3.2", + "express": "^4.18.2", + "puppeteer": "^22.8.1", + "puppeteer-extra": "^3.3.6", + "puppeteer-extra-plugin-stealth": "^2.11.1" } } \ No newline at end of file -- GitLab