const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({ headless: false });
  const page = await browser.newPage();
  
  // 使用已登录的 Chrome 用户数据
  await page.goto('https://www.dmit.io/products', {
    waitUntil: 'networkidle0',
    timeout: 30000
  });
  
  await new Promise(resolve => setTimeout(resolve, 3000));
  
  const products = await page.evaluate(() => {
    const results = [];
    
    // 提取所有产品信息
    document.querySelectorAll('[class*="product"], .card, div').forEach(el => {
      const text = el.textContent;
      if (text.includes('USD') || text.includes('$')) {
        const name = el.querySelector('h3, h4, .title, [class*="name"]')?.textContent.trim();
        const price = text.match(/\$?(\d+\.?\d*)\s*USD/)?.[0];
        if (name && price) {
          results.push({ name, price });
        }
      }
    });
    
    return results;
  });
  
  console.log(JSON.stringify(products, null, 2));
  await browser.close();
})();
