Назад к блогу
Примеры использования

E-Commerce Automation with Cloud Browsers

How to build reliable e-commerce automation for price monitoring, inventory tracking, and competitive intelligence using cloud browsers.

Introduction

E-commerce platforms are among the most heavily protected websites. They employ sophisticated bot detection to prevent price scraping, inventory hoarding, and unauthorized automation. Cloud browsers with realistic fingerprints provide the foundation for reliable e-commerce automation.

Common E-Commerce Automation Use Cases

Price Monitoring

Track competitor prices across multiple retailers:

async function scrapePrice(browser, url) {
  const page = await browser.newPage();

  try {
    await page.goto(url, { waitUntil: 'networkidle2', timeout: 30000 });

    // Wait for price element to render (SPAs may load prices async)
    await page.waitForSelector('[data-price], .price, .product-price', {
      timeout: 10000,
    });

    const priceData = await page.evaluate(() => {
      // Try multiple common price selectors
      const selectors = [
        '[data-price]',
        '.price .current',
        '.product-price',
        '[itemprop="price"]',
        '.a-price .a-offscreen', // Amazon
      ];

      for (const sel of selectors) {
        const el = document.querySelector(sel);
        if (el) {
          const text = el.textContent.trim();
          const price = parseFloat(text.replace(/[^0-9.]/g, ''));
          if (!isNaN(price)) return { price, currency: text.replace(/[0-9.,\s]/g, '').trim() };
        }
      }

      return null;
    });

    return { url, ...priceData, timestamp: new Date().toISOString() };
  } finally {
    await page.close();
  }
}

Inventory Tracking

Monitor stock levels and availability:

async function checkInventory(page, url) {
  await page.goto(url, { waitUntil: 'networkidle2' });

  return page.evaluate(() => {
    // Check for out-of-stock indicators
    const outOfStockIndicators = [
      'out of stock',
      'sold out',
      'currently unavailable',
      'notify me',
    ];

    const bodyText = document.body.textContent.toLowerCase();
    const isOutOfStock = outOfStockIndicators.some(text => bodyText.includes(text));

    // Check add-to-cart button
    const addToCart = document.querySelector(
      '[data-action="add-to-cart"], .add-to-cart, #add-to-cart'
    );
    const cartButtonDisabled = addToCart?.disabled || addToCart?.getAttribute('aria-disabled') === 'true';

    return {
      inStock: !isOutOfStock && !cartButtonDisabled,
      indicators: { isOutOfStock, cartButtonDisabled },
    };
  });
}

Product Data Extraction

Extract comprehensive product information:

async function extractProduct(page, url) {
  await page.goto(url, { waitUntil: 'networkidle2' });

  // Check for structured data first (most reliable)
  const structuredData = await page.evaluate(() => {
    const ldJson = document.querySelector('script[type="application/ld+json"]');
    if (ldJson) {
      try {
        const data = JSON.parse(ldJson.textContent);
        if (data['@type'] === 'Product' || data['@type']?.includes('Product')) {
          return data;
        }
      } catch (e) {}
    }
    return null;
  });

  if (structuredData) {
    return {
      title: structuredData.name,
      price: structuredData.offers?.price,
      currency: structuredData.offers?.priceCurrency,
      availability: structuredData.offers?.availability,
      rating: structuredData.aggregateRating?.ratingValue,
      reviewCount: structuredData.aggregateRating?.reviewCount,
      image: structuredData.image,
      description: structuredData.description,
    };
  }

  // Fall back to DOM extraction
  return page.evaluate(() => ({
    title: document.querySelector('h1')?.textContent?.trim(),
    price: document.querySelector('[itemprop="price"]')?.textContent?.trim(),
    // ... more selectors
  }));
}

Handling E-Commerce Challenges

Geo-Restricted Pricing

Many retailers show different prices by region:

const regions = [
  { name: 'US', proxy: 'socks5h://user:pass@us-proxy:1080' },
  { name: 'UK', proxy: 'socks5h://user:pass@uk-proxy:1080' },
  { name: 'DE', proxy: 'socks5h://user:pass@de-proxy:1080' },
];

async function compareRegionalPrices(productUrl) {
  const prices = [];

  for (const region of regions) {
    const browser = await puppeteer.connect({
      browserWSEndpoint:
        `wss://bots.win/ws?apiKey=YOUR_API_KEY&proxy=${encodeURIComponent(region.proxy)}`,
    });

    const page = await browser.newPage();
    const price = await scrapePrice(page, productUrl);
    prices.push({ region: region.name, ...price });

    await browser.close();
  }

  return prices;
}

Dynamic Content Loading

E-commerce sites often load product data asynchronously:

// Wait for the price API response
const priceResponse = await page.waitForResponse(
  res => res.url().includes('/api/product/price') && res.status() === 200,
  { timeout: 15000 }
);
const priceData = await priceResponse.json();

Anti-Bot Challenges

E-commerce sites commonly use:

  • Cloudflare - Browser integrity checks
  • PerimeterX/HUMAN - Behavioral analysis
  • DataDome - Real-time bot detection
  • Akamai Bot Manager - Request analysis

Cloud browsers with complete profiles handle the fingerprint layer. Combine with residential proxies and natural timing for best results.

Best Practices

  1. Use structured data (JSON-LD) when available for the most reliable extraction
  2. Rotate proxies per session to avoid IP-based rate limiting
  3. Implement rate limiting to avoid triggering detection
  4. Cache results to reduce unnecessary requests
  5. Monitor for site changes since selectors break when sites update
  6. Use regional proxies for geo-specific pricing
  7. Validate prices against reasonable ranges to catch extraction errors
#ecommerce#price-monitoring#automation#scraping