You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
148 lines
4.6 KiB
148 lines
4.6 KiB
#!/usr/bin/env node
|
|
/**
|
|
* 使用 Playwright 从 clawhub.com 下载 agent-browser skill
|
|
*/
|
|
|
|
import { chromium } from 'playwright';
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
async function downloadAgentBrowser() {
|
|
const browser = await chromium.launch({ headless: true });
|
|
const context = await browser.newContext({
|
|
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
|
|
});
|
|
const page = await context.newPage();
|
|
|
|
try {
|
|
// 首先访问 clawhub.com 的 agent-browser 页面
|
|
const url = 'https://clawhub.com/skill/agent-browser';
|
|
console.log(`🌐 正在访问: ${url}`);
|
|
await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30000 });
|
|
|
|
// 获取页面标题
|
|
const title = await page.title();
|
|
console.log(`📄 页面标题: ${title}`);
|
|
|
|
// 获取页面内容
|
|
const content = await page.content();
|
|
const text = await page.evaluate(() => document.body.innerText);
|
|
|
|
// 截图保存
|
|
const screenshotPath = path.join(process.cwd(), 'clawhub-page.png');
|
|
await page.screenshot({ path: screenshotPath, fullPage: true });
|
|
console.log(`📸 页面截图已保存: ${screenshotPath}`);
|
|
|
|
// 尝试查找下载链接或 git 仓库信息
|
|
console.log('\n🔍 正在查找下载信息...');
|
|
|
|
const pageData = await page.evaluate(() => {
|
|
// 查找所有链接
|
|
const links = Array.from(document.querySelectorAll('a')).map(a => ({
|
|
text: a.textContent?.trim() || '',
|
|
href: a.href
|
|
}));
|
|
|
|
// 查找代码块
|
|
const codeBlocks = Array.from(document.querySelectorAll('pre, code')).map(el => ({
|
|
text: el.textContent?.trim() || '',
|
|
tag: el.tagName
|
|
}));
|
|
|
|
// 查找所有文本
|
|
const allText = document.body.innerText;
|
|
|
|
return { links, codeBlocks, allText };
|
|
});
|
|
|
|
// 保存页面数据到文件
|
|
const dataPath = path.join(process.cwd(), 'clawhub-data.json');
|
|
fs.writeFileSync(dataPath, JSON.stringify(pageData, null, 2));
|
|
console.log(`📊 页面数据已保存: ${dataPath}`);
|
|
|
|
// 分析查找有用的信息
|
|
console.log('\n📋 发现的链接:');
|
|
const gitLinks = pageData.links.filter(l =>
|
|
l.href.includes('github.com') ||
|
|
l.href.includes('gitlab.com') ||
|
|
l.href.includes('git')
|
|
);
|
|
|
|
if (gitLinks.length > 0) {
|
|
gitLinks.forEach(link => {
|
|
console.log(` - ${link.text}: ${link.href}`);
|
|
});
|
|
} else {
|
|
console.log(' 未找到 Git 仓库链接');
|
|
}
|
|
|
|
// 查找 install 命令
|
|
console.log('\n🔧 查找安装命令:');
|
|
const installCommands = pageData.codeBlocks.filter(cb =>
|
|
cb.text.includes('clawhub install') ||
|
|
cb.text.includes('git clone')
|
|
);
|
|
|
|
if (installCommands.length > 0) {
|
|
installCommands.forEach(cmd => {
|
|
console.log(` ${cmd.text.substring(0, 200)}...`);
|
|
});
|
|
}
|
|
|
|
// 尝试直接从页面查找 skill 的文件结构
|
|
console.log('\n📁 尝试查找 skill 文件...');
|
|
|
|
// 尝试访问可能的文件列表页面
|
|
try {
|
|
const filesUrl = 'https://clawhub.com/skill/agent-browser/files';
|
|
console.log(` 尝试访问: ${filesUrl}`);
|
|
await page.goto(filesUrl, { waitUntil: 'domcontentloaded', timeout: 15000 });
|
|
|
|
const filesScreenshot = path.join(process.cwd(), 'clawhub-files.png');
|
|
await page.screenshot({ path: filesScreenshot, fullPage: true });
|
|
console.log(` 📸 文件页面截图: ${filesScreenshot}`);
|
|
|
|
const filesContent = await page.content();
|
|
const filesDataPath = path.join(process.cwd(), 'clawhub-files.html');
|
|
fs.writeFileSync(filesDataPath, filesContent);
|
|
console.log(` 📄 文件页面HTML: ${filesDataPath}`);
|
|
|
|
} catch (err) {
|
|
console.log(` ⚠️ 文件页面访问失败: ${err.message}`);
|
|
}
|
|
|
|
console.log('\n✅ 页面访问完成!');
|
|
console.log(`📸 截图: ${screenshotPath}`);
|
|
console.log(`📊 数据: ${dataPath}`);
|
|
|
|
return {
|
|
success: true,
|
|
title,
|
|
screenshotPath,
|
|
dataPath
|
|
};
|
|
|
|
} catch (error) {
|
|
console.error(`❌ 访问失败: ${error.message}`);
|
|
return {
|
|
success: false,
|
|
error: error.message
|
|
};
|
|
} finally {
|
|
await browser.close();
|
|
}
|
|
}
|
|
|
|
// 运行
|
|
downloadAgentBrowser().then(result => {
|
|
if (result.success) {
|
|
console.log('\n🎉 任务完成!');
|
|
process.exit(0);
|
|
} else {
|
|
console.log('\n❌ 任务失败');
|
|
process.exit(1);
|
|
}
|
|
}).catch(error => {
|
|
console.error('Error:', error);
|
|
process.exit(1);
|
|
});
|
|
|