提交 552bcb29 编写于 作者: R root

Wed Jul 2 17:49:00 CST 2025 inscode

上级 669eac6d
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}"
......
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(`
<h1>欢迎来到 InsCode Node.js 示例</h1>
<p>这是一个使用Express和Puppeteer的示例项目</p>
<ul>
<li><a href="/scrape">测试Puppeteer抓取</a></li>
<li><a href="/api/status">API状态</a></li>
</ul>
`);
});
// 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(`
<h2>Puppeteer抓取结果</h2>
<p>Example.com的标题是: ${title}</p>
<a href="/">返回首页</a>
`);
} 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
{
"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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册