config: Add 34 files
This commit is contained in:
77
debug-pbtech3.js
Normal file
77
debug-pbtech3.js
Normal file
@@ -0,0 +1,77 @@
|
||||
const puppeteer = require('puppeteer');
|
||||
|
||||
async function debugPBTech() {
|
||||
const browser = await puppeteer.launch({
|
||||
headless: 'new',
|
||||
args: ['--no-sandbox', '--disable-setuid-sandbox']
|
||||
});
|
||||
|
||||
const page = await browser.newPage();
|
||||
await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36');
|
||||
|
||||
console.log('Loading PB Tech CPU page...');
|
||||
await page.goto('https://www.pbtech.co.nz/category/components/cpus', {
|
||||
waitUntil: 'networkidle2',
|
||||
timeout: 30000
|
||||
});
|
||||
|
||||
console.log('\n=== EXTRACTING PRODUCT INFO BETTER ===');
|
||||
|
||||
const info = await page.evaluate(() => {
|
||||
const buttons = document.querySelectorAll('[data-product-id]');
|
||||
const results = [];
|
||||
|
||||
buttons.forEach((btn, index) => {
|
||||
if (index >= 3) return;
|
||||
|
||||
const productId = btn.getAttribute('data-product-id');
|
||||
const price = btn.getAttribute('data-price');
|
||||
|
||||
// Go up several levels to find the card
|
||||
let card = btn;
|
||||
for (let i = 0; i < 10; i++) {
|
||||
card = card.parentElement;
|
||||
if (!card) break;
|
||||
|
||||
// Check if this container has product info
|
||||
const links = card.querySelectorAll('a');
|
||||
const hasProductLink = Array.from(links).some(a =>
|
||||
a.href && a.href.includes(productId)
|
||||
);
|
||||
|
||||
if (hasProductLink) {
|
||||
// Found the card!
|
||||
const productLink = Array.from(links).find(a => a.href && a.href.includes(productId));
|
||||
|
||||
results.push({
|
||||
productId: productId,
|
||||
price: price,
|
||||
name: productLink?.textContent?.trim() || productLink?.title,
|
||||
href: productLink?.href,
|
||||
cardHTML: card.outerHTML.substring(0, 1200),
|
||||
cardClass: card.className,
|
||||
level: i
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return results;
|
||||
});
|
||||
|
||||
console.log('\nFound products:');
|
||||
info.forEach((p, i) => {
|
||||
console.log(`\n--- Product ${i + 1} ---`);
|
||||
console.log(`Product ID: ${p.productId}`);
|
||||
console.log(`Price: $${p.price}`);
|
||||
console.log(`Name: ${p.name}`);
|
||||
console.log(`Link: ${p.href}`);
|
||||
console.log(`Card level: ${p.level} parents up`);
|
||||
console.log(`Card class: ${p.cardClass}`);
|
||||
});
|
||||
|
||||
await browser.close();
|
||||
}
|
||||
|
||||
debugPBTech().catch(console.error);
|
Reference in New Issue
Block a user