48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
|
|
const puppeteer = require('puppeteer-extra');
|
||
|
|
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
|
||
|
|
puppeteer.use(StealthPlugin());
|
||
|
|
|
||
|
|
(async () => {
|
||
|
|
const browser = await puppeteer.launch({
|
||
|
|
headless: false,
|
||
|
|
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
||
|
|
});
|
||
|
|
const page = await browser.newPage();
|
||
|
|
|
||
|
|
console.log('正在访问页面...');
|
||
|
|
await page.goto('https://my.rfchost.com/index.php?rp=/store/jp2-tier-1-international-optimization-network', {
|
||
|
|
waitUntil: 'networkidle0',
|
||
|
|
timeout: 60000
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log('等待10秒让页面完全加载...');
|
||
|
|
await new Promise(resolve => setTimeout(resolve, 10000));
|
||
|
|
|
||
|
|
// 检查页面标题
|
||
|
|
const title = await page.title();
|
||
|
|
console.log('页面标题:', title);
|
||
|
|
|
||
|
|
// 提取产品信息
|
||
|
|
const products = await page.evaluate(() => {
|
||
|
|
const results = [];
|
||
|
|
const links = document.querySelectorAll('a');
|
||
|
|
links.forEach(a => {
|
||
|
|
if (a.href && a.href.includes('pid=')) {
|
||
|
|
const url = new URL(a.href);
|
||
|
|
const pid = url.searchParams.get('pid');
|
||
|
|
const card = a.closest('.product, .card, .col-md-4, div[class*="product"]');
|
||
|
|
const nameEl = card?.querySelector('h3, h4, .product-name, .product-title');
|
||
|
|
const name = nameEl?.textContent.trim();
|
||
|
|
if (pid) {
|
||
|
|
results.push({ name: name || 'Unknown', pid, href: a.href });
|
||
|
|
}
|
||
|
|
}
|
||
|
|
});
|
||
|
|
return results;
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log('找到的产品:', JSON.stringify(products, null, 2));
|
||
|
|
|
||
|
|
await browser.close();
|
||
|
|
})();
|