功能: - 网页截图(全页或视口) - HTML代码提取 - 自动滚动加载动态内容 - 自定义视口大小 - Web界面和RESTful API - 支持两种后端: agent-browser 和 Playwright - Docker部署支持 包含: - Flask REST API - 前端Web界面 - 测试脚本 - 安装脚本 - Dockerfile和docker-compose - systemd服务配置
480 lines
15 KiB
HTML
480 lines
15 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Web Capture - 网页截图与代码提取</title>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
min-height: 100vh;
|
|
padding: 20px;
|
|
}
|
|
|
|
.container {
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
.header {
|
|
text-align: center;
|
|
color: white;
|
|
margin-bottom: 30px;
|
|
}
|
|
|
|
.header h1 {
|
|
font-size: 2.5em;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.header p {
|
|
opacity: 0.9;
|
|
}
|
|
|
|
.card {
|
|
background: white;
|
|
border-radius: 16px;
|
|
padding: 30px;
|
|
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.form-group {
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
label {
|
|
display: block;
|
|
font-weight: 600;
|
|
margin-bottom: 8px;
|
|
color: #333;
|
|
}
|
|
|
|
input[type="text"],
|
|
input[type="number"],
|
|
select {
|
|
width: 100%;
|
|
padding: 12px;
|
|
border: 2px solid #e0e0e0;
|
|
border-radius: 8px;
|
|
font-size: 16px;
|
|
transition: border-color 0.3s;
|
|
}
|
|
|
|
input:focus,
|
|
select:focus {
|
|
outline: none;
|
|
border-color: #667eea;
|
|
}
|
|
|
|
.radio-group {
|
|
display: flex;
|
|
gap: 20px;
|
|
}
|
|
|
|
.radio-label {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.radio-label input[type="radio"] {
|
|
width: 20px;
|
|
height: 20px;
|
|
}
|
|
|
|
.checkbox-group {
|
|
display: flex;
|
|
gap: 20px;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.checkbox-label {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.checkbox-label input[type="checkbox"] {
|
|
width: 20px;
|
|
height: 20px;
|
|
}
|
|
|
|
.row {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
|
|
gap: 15px;
|
|
}
|
|
|
|
.btn {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
border: none;
|
|
padding: 15px 40px;
|
|
font-size: 18px;
|
|
font-weight: 600;
|
|
border-radius: 8px;
|
|
cursor: pointer;
|
|
transition: transform 0.2s, box-shadow 0.2s;
|
|
width: 100%;
|
|
margin-top: 10px;
|
|
}
|
|
|
|
.btn:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 10px 30px rgba(102, 126, 234, 0.4);
|
|
}
|
|
|
|
.btn:active {
|
|
transform: translateY(0);
|
|
}
|
|
|
|
.btn:disabled {
|
|
opacity: 0.6;
|
|
cursor: not-allowed;
|
|
transform: none;
|
|
}
|
|
|
|
.loading {
|
|
display: none;
|
|
text-align: center;
|
|
padding: 20px;
|
|
}
|
|
|
|
.loading.active {
|
|
display: block;
|
|
}
|
|
|
|
.spinner {
|
|
border: 4px solid #f3f3f3;
|
|
border-top: 4px solid #667eea;
|
|
border-radius: 50%;
|
|
width: 40px;
|
|
height: 40px;
|
|
animation: spin 1s linear infinite;
|
|
margin: 0 auto 15px;
|
|
}
|
|
|
|
@keyframes spin {
|
|
0% { transform: rotate(0deg); }
|
|
100% { transform: rotate(360deg); }
|
|
}
|
|
|
|
.result {
|
|
display: none;
|
|
}
|
|
|
|
.result.active {
|
|
display: block;
|
|
}
|
|
|
|
.result-image {
|
|
width: 100%;
|
|
border-radius: 8px;
|
|
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.result-code {
|
|
background: #1e1e1e;
|
|
color: #d4d4d4;
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
overflow-x: auto;
|
|
max-height: 600px;
|
|
font-family: 'Courier New', monospace;
|
|
font-size: 14px;
|
|
line-height: 1.6;
|
|
}
|
|
|
|
.result-code pre {
|
|
margin: 0;
|
|
white-space: pre-wrap;
|
|
word-wrap: break-word;
|
|
}
|
|
|
|
.actions {
|
|
margin-top: 20px;
|
|
display: flex;
|
|
gap: 10px;
|
|
}
|
|
|
|
.btn-secondary {
|
|
background: #6c757d;
|
|
padding: 10px 20px;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.error {
|
|
background: #fee;
|
|
border: 1px solid #fcc;
|
|
color: #c00;
|
|
padding: 15px;
|
|
border-radius: 8px;
|
|
margin-top: 20px;
|
|
display: none;
|
|
}
|
|
|
|
.error.active {
|
|
display: block;
|
|
}
|
|
|
|
.api-docs {
|
|
margin-top: 30px;
|
|
padding: 20px;
|
|
background: #f8f9fa;
|
|
border-radius: 8px;
|
|
}
|
|
|
|
.api-docs h3 {
|
|
margin-bottom: 15px;
|
|
color: #333;
|
|
}
|
|
|
|
.api-docs code {
|
|
background: #e9ecef;
|
|
padding: 2px 6px;
|
|
border-radius: 4px;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.api-docs pre {
|
|
background: #1e1e1e;
|
|
color: #d4d4d4;
|
|
padding: 15px;
|
|
border-radius: 8px;
|
|
overflow-x: auto;
|
|
margin-top: 10px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="header">
|
|
<h1>🌐 Web Capture</h1>
|
|
<p>网页截图与代码提取服务</p>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<form id="captureForm">
|
|
<div class="form-group">
|
|
<label for="url">目标网址</label>
|
|
<input type="text" id="url" placeholder="https://example.com" required>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label>操作类型</label>
|
|
<div class="radio-group">
|
|
<label class="radio-label">
|
|
<input type="radio" name="action" value="screenshot" checked>
|
|
📸 截图
|
|
</label>
|
|
<label class="radio-label">
|
|
<input type="radio" name="action" value="html">
|
|
📄 提取HTML
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label>高级选项</label>
|
|
<div class="checkbox-group">
|
|
<label class="checkbox-label">
|
|
<input type="checkbox" id="fullPage">
|
|
全页截图
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label>滚动设置(用于加载动态内容)</label>
|
|
<div class="row">
|
|
<div>
|
|
<label for="scrollTimes">滚动次数</label>
|
|
<input type="number" id="scrollTimes" value="0" min="0" max="20">
|
|
</div>
|
|
<div>
|
|
<label for="scrollDelay">滚动间隔(ms)</label>
|
|
<input type="number" id="scrollDelay" value="1000" min="500" max="5000" step="100">
|
|
</div>
|
|
<div>
|
|
<label for="waitTime">页面加载等待(ms)</label>
|
|
<input type="number" id="waitTime" value="2000" min="0" max="10000" step="500">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label>视口大小</label>
|
|
<div class="row">
|
|
<div>
|
|
<label for="viewportWidth">宽度</label>
|
|
<input type="number" id="viewportWidth" value="1920" min="320" max="3840">
|
|
</div>
|
|
<div>
|
|
<label for="viewportHeight">高度</label>
|
|
<input type="number" id="viewportHeight" value="1080" min="240" max="2160">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<button type="submit" class="btn" id="submitBtn">
|
|
🚀 开始捕获
|
|
</button>
|
|
</form>
|
|
|
|
<div class="loading" id="loading">
|
|
<div class="spinner"></div>
|
|
<p>正在处理,请稍候...</p>
|
|
</div>
|
|
|
|
<div class="error" id="error"></div>
|
|
|
|
<div class="result" id="result">
|
|
<h3 style="margin-bottom: 15px;">捕获结果</h3>
|
|
<div id="resultContent"></div>
|
|
<div class="actions">
|
|
<button class="btn btn-secondary" onclick="downloadResult()">💾 下载</button>
|
|
<button class="btn btn-secondary" onclick="copyResult()">📋 复制</button>
|
|
<button class="btn btn-secondary" onclick="resetForm()">🔄 重新捕获</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card api-docs">
|
|
<h3>📚 API 文档</h3>
|
|
<p>POST /api/capture</p>
|
|
<pre><code>{
|
|
"url": "https://example.com",
|
|
"action": "screenshot", // 或 "html"
|
|
"scroll_times": 3,
|
|
"scroll_delay": 1000,
|
|
"full_page": true,
|
|
"viewport": {"width": 1920, "height": 1080},
|
|
"wait_time": 2000
|
|
}</code></pre>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const form = document.getElementById('captureForm');
|
|
const loading = document.getElementById('loading');
|
|
const result = document.getElementById('result');
|
|
const error = document.getElementById('error');
|
|
const submitBtn = document.getElementById('submitBtn');
|
|
let currentData = null;
|
|
let currentBlob = null;
|
|
|
|
form.addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
|
|
const url = document.getElementById('url').value;
|
|
const action = document.querySelector('input[name="action"]:checked').value;
|
|
const fullPage = document.getElementById('fullPage').checked;
|
|
const scrollTimes = parseInt(document.getElementById('scrollTimes').value);
|
|
const scrollDelay = parseInt(document.getElementById('scrollDelay').value);
|
|
const waitTime = parseInt(document.getElementById('waitTime').value);
|
|
const viewportWidth = parseInt(document.getElementById('viewportWidth').value);
|
|
const viewportHeight = parseInt(document.getElementById('viewportHeight').value);
|
|
|
|
currentData = {
|
|
url,
|
|
action,
|
|
scroll_times: scrollTimes,
|
|
scroll_delay: scrollDelay,
|
|
full_page: fullPage,
|
|
wait_time: waitTime,
|
|
viewport: {
|
|
width: viewportWidth,
|
|
height: viewportHeight
|
|
}
|
|
};
|
|
|
|
// 显示加载
|
|
loading.classList.add('active');
|
|
result.classList.remove('active');
|
|
error.classList.remove('active');
|
|
submitBtn.disabled = true;
|
|
|
|
try {
|
|
const response = await fetch('/api/capture', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify(currentData)
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const errData = await response.json();
|
|
throw new Error(errData.error || '请求失败');
|
|
}
|
|
|
|
if (action === 'screenshot') {
|
|
currentBlob = await response.blob();
|
|
const imageUrl = URL.createObjectURL(currentBlob);
|
|
document.getElementById('resultContent').innerHTML =
|
|
`<img src="${imageUrl}" class="result-image" alt="截图结果">`;
|
|
} else {
|
|
const data = await response.json();
|
|
currentBlob = new Blob([data.html], { type: 'text/html' });
|
|
document.getElementById('resultContent').innerHTML =
|
|
`<div class="result-code"><pre>${escapeHtml(data.html)}</pre></div>`;
|
|
}
|
|
|
|
result.classList.add('active');
|
|
} catch (err) {
|
|
error.textContent = '❌ ' + err.message;
|
|
error.classList.add('active');
|
|
} finally {
|
|
loading.classList.remove('active');
|
|
submitBtn.disabled = false;
|
|
}
|
|
});
|
|
|
|
function escapeHtml(text) {
|
|
const div = document.createElement('div');
|
|
div.textContent = text;
|
|
return div.innerHTML;
|
|
}
|
|
|
|
function downloadResult() {
|
|
if (!currentBlob) return;
|
|
|
|
const url = URL.createObjectURL(currentBlob);
|
|
const a = document.createElement('a');
|
|
a.href = url;
|
|
a.download = currentData.action === 'screenshot' ? 'screenshot.png' : 'page.html';
|
|
a.click();
|
|
URL.revokeObjectURL(url);
|
|
}
|
|
|
|
function copyResult() {
|
|
if (!currentBlob) return;
|
|
|
|
const reader = new FileReader();
|
|
reader.onload = () => {
|
|
navigator.clipboard.writeText(reader.result).then(() => {
|
|
alert('已复制到剪贴板');
|
|
});
|
|
};
|
|
reader.readAsText(currentBlob);
|
|
}
|
|
|
|
function resetForm() {
|
|
result.classList.remove('active');
|
|
error.classList.remove('active');
|
|
currentData = null;
|
|
currentBlob = null;
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |