import { createStealthBrowser, createStealthContext, waitForPageLoad, isCloudflareChallenge, waitForCloudflareChallenge } from './src/utils/stealthBrowser'; import { getRandomProxy } from './src/utils/proxyManager'; import { dutchieTemplate } from './src/scrapers/templates/dutchie'; import { pool } from './src/db/migrate'; async function testDutchieTemplate() { console.log('๐Ÿงช Testing Dutchie scraper template\n'); const baseUrl = 'https://dutchie.com/dispensary/sol-flower-dispensary'; const category = 'Flower'; // Build category URL using template const categoryUrl = dutchieTemplate.buildCategoryUrl(baseUrl, category); console.log(`๐Ÿ“‚ Category: ${category}`); console.log(`๐Ÿ”— URL: ${categoryUrl}\n`); // Get proxy const proxy = await getRandomProxy(); console.log(`๐Ÿ” Using proxy: ${proxy?.server || 'none'}\n`); const browser = await createStealthBrowser({ proxy: proxy || undefined, headless: true }); try { const context = await createStealthContext(browser, { state: 'Arizona' }); const page = await context.newPage(); console.log('๐ŸŒ Loading page...'); await page.goto(categoryUrl, { waitUntil: 'domcontentloaded', timeout: 60000 }); // Check for Cloudflare if (await isCloudflareChallenge(page)) { console.log('๐Ÿ›ก๏ธ Cloudflare detected, waiting...'); const passed = await waitForCloudflareChallenge(page, 60000); if (!passed) { console.log('โŒ Failed to pass Cloudflare'); await browser.close(); await pool.end(); return; } } await waitForPageLoad(page); // Wait for content await page.waitForTimeout(3000); console.log('\n๐Ÿ“ฆ Extracting products using Dutchie template...'); const products = await dutchieTemplate.extractProducts(page); console.log(`\nโœ… Found ${products.length} products!\n`); if (products.length > 0) { console.log('First 10 products:'); products.slice(0, 10).forEach((product, i) => { console.log(`\n${i + 1}. ${product.name}`); if (product.brand) console.log(` Brand: ${product.brand}`); if (product.price) console.log(` Price: $${product.price}`); console.log(` URL: ${product.product_url}`); }); } } catch (error) { console.error('โŒ Error:', error); } finally { await browser.close(); await pool.end(); } } testDutchieTemplate();