import puppeteer from 'puppeteer'; async function sleep(ms: number): Promise { return new Promise(resolve => setTimeout(resolve, ms)); } async function main() { console.log('Navigating to https://shop.bestdispensary.com/brands'); const browser = await puppeteer.launch({ headless: true, args: ['--no-sandbox', '--disable-setuid-sandbox'], }); const page = await browser.newPage(); await page.setViewport({ width: 1920, height: 1080 }); await page.setRequestInterception(true); page.on('request', (req) => { if (['image', 'font', 'media'].includes(req.resourceType())) { req.abort(); } else { req.continue(); } }); // Go directly to the brands page await page.goto('https://shop.bestdispensary.com/brands', { waitUntil: 'networkidle2', timeout: 60000 }); await sleep(3000); // Bypass age gate if present const ageGate = await page.$('[data-testid="age-gate-modal"]'); if (ageGate) { console.log('Age gate detected, bypassing...'); const btn = await page.$('[data-testid="age-gate-submit-button"]'); if (btn) await btn.click(); await sleep(2000); } console.log('Current URL:', page.url()); // Scroll to load all content console.log('\nScrolling to load all brands...'); let previousHeight = 0; for (let i = 0; i < 20; i++) { await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight)); await sleep(1500); const currentHeight = await page.evaluate(() => document.body.scrollHeight); if (currentHeight === previousHeight) { console.log(` Scroll ${i+1}: No new content`); break; } previousHeight = currentHeight; const brandCount = await page.evaluate(() => document.querySelectorAll('a[href*="/brand/"]').length ); console.log(` Scroll ${i+1}: height=${currentHeight}, brand links=${brandCount}`); } // Get all brand links const brands = await page.evaluate(() => { const results: { name: string; href: string }[] = []; const seen = new Set(); document.querySelectorAll('a[href*="/brand/"]').forEach((a: Element) => { const href = a.getAttribute('href') || ''; if (seen.has(href)) return; seen.add(href); const name = a.textContent?.trim() || href.split('/brand/')[1] || ''; results.push({ name, href }); }); return results; }); console.log(`\nFound ${brands.length} brands:`); brands.forEach(b => console.log(` - ${b.name} (${b.href})`)); // Take screenshot await page.screenshot({ path: '/tmp/bestdispensary-brands.png', fullPage: true }); console.log('\nScreenshot saved to /tmp/bestdispensary-brands.png'); await browser.close(); } main().catch(console.error);