\n```\n\n## 3) Choose your scraping approach\n### A. Static HTML pages\nUse Python with `requests` + `BeautifulSoup`.\n\n```python\nimport requests\nfrom bs4 import BeautifulSoup\nimport json\n\nurl = \"https://example.com/product/123\"\nheaders = {\"User-Agent\": \"Mozilla/5.0\"}\nhtml = requests.get(url, headers=headers).text\nsoup = BeautifulSoup(html, \"html.parser\")\n\n# Try JSON-LD first\nfor script in soup.find_all(\"script\", type=\"application/ld+json\"):\n try:\n data = json.loads(script.string)\n if isinstance(data, dict) and \"aggregateRating\" in data:\n print(data[\"aggregateRating\"])\n except Exception:\n pass\n```\n\n### B. JavaScript-rendered pages\nUse a browser automation tool like **Playwright** or **Selenium** if the ratings are loaded dynamically.\n\nExample with Playwright:\n```python\nfrom playwright.sync_api import sync_playwright\n\nurl = \"https://example.com/product/123\"\n\nwith sync_playwright() as p:\n browser = p.chromium.launch(headless=True)\n page = browser.new_page()\n page.goto(url, wait_until=\"networkidle\")\n html = page.content()\n print(html)\n browser.close()\n```\n\n## 4) Inspect the page for API calls\nOften the ratings come from an XHR/fetch request:\n- Open browser DevTools → **Network**\n- Filter by **Fetch/XHR**\n- Reload page and look for endpoints returning JSON review data\n\nIf you find such an endpoint, it may be much easier to request directly than parsing the page.\n\n## 5) Extract what you need\nTypical fields:\n- average rating\n- number of ratings/reviews\n- individual review stars\n- review text\n- review date\n\nExample selectors may vary by site:\n```python\nrating = soup.select_one(\".rating\").get_text(strip=True)\nreview_count = soup.select_one(\".review-count\").get_text(strip=True)\n```\n\n## 6) Handle anti-bot measures\nBe careful with:\n- rate limiting\n- CAPTCHAs\n- login walls\n- session cookies\n\nUse:\n- delays between requests\n- retries with backoff\n- caching\n- rotating only if permitted and ethical\n\n## 7) Store the data\nSave to:\n- CSV for simple analysis\n- JSON for nested review structures\n- a database for large-scale scraping\n\nExample CSV output:\n```python\nimport csv\n\nwith open(\"ratings.csv\", \"w\", newline=\"\", encoding=\"utf-8\") as f:\n writer = csv.DictWriter(f, fieldnames=[\"product\", \"rating\", \"review_count\"])\n writer.writeheader()\n writer.writerow({\"product\": \"Widget\", \"rating\": 4.6, \"review_count\": 128})\n```\n\n## 8) A safer alternative: use APIs or data providers\nMany ecommerce platforms offer:\n- official APIs\n- partner feeds\n- review export features\n\nExamples:\n- Shopify apps / admin APIs\n- Amazon SP-API for authorized sellers\n- Trustpilot / Bazaarvoice APIs where applicable\n\n---\n\nIf you want, I can give you:\n1. a **Python script template** for scraping ratings from a product page, or \n2. a **site-specific approach** if you tell me which ecommerce site you’re targeting."}}}

Prompt

How do I scrape customer ratings from ecommerce sites?

Latest observation

Jul 15, 2026 · OpenAI APIWeb search: off

Scraping customer ratings from ecommerce sites can be done, but the safest and most reliable approach is to use the site’s official API or export tools first. If scraping is allowed by the site’s Terms of Service and robots rules, here’s a practical way to do it.

1) Check legality and access rules

Before scraping:

  • Review the site’s Terms of Service
  • Check robots.txt
  • Make sure you’re not collecting personal data you shouldn’t
  • Use reasonable request rates to avoid disrupting the site

2) Prefer structured sources

Customer ratings often appear in places that are easier to extract than the visible page:

  • JSON-LD / structured data in the HTML
  • Embedded API responses loaded by the page
  • Hidden scripts containing review data

Example of structured rating data in HTML:

<script type="application/ld+json">
{
  "@type": "Product",
  "aggregateRating": {
    "ratingValue": "4.6",
    "reviewCount": "128"
  }
}
</script>

3) Choose your scraping approach

A. Static HTML pages

Use Python with requests + BeautifulSoup.

import requests
from bs4 import BeautifulSoup
import json

url = "https://example.com/product/123"
headers = {"User-Agent": "Mozilla/5.0"}
html = requests.get(url, headers=headers).text
soup = BeautifulSoup(html, "html.parser")

# Try JSON-LD first
for script in soup.find_all("script", type="application/ld+json"):
    try:
        data = json.loads(script.string)
        if isinstance(data, dict) and "aggregateRating" in data:
            print(data["aggregateRating"])
    except Exception:
        pass

B. JavaScript-rendered pages

Use a browser automation tool like Playwright or Selenium if the ratings are loaded dynamically.

Example with Playwright:

from playwright.sync_api import sync_playwright

url = "https://example.com/product/123"

with sync_playwright() as p:
    browser = p.chromium.launch(headless=True)
    page = browser.new_page()
    page.goto(url, wait_until="networkidle")
    html = page.content()
    print(html)
    browser.close()

4) Inspect the page for API calls

Often the ratings come from an XHR/fetch request:

  • Open browser DevTools → Network
  • Filter by Fetch/XHR
  • Reload page and look for endpoints returning JSON review data

If you find such an endpoint, it may be much easier to request directly than parsing the page.

5) Extract what you need

Typical fields:

  • average rating
  • number of ratings/reviews
  • individual review stars
  • review text
  • review date

Example selectors may vary by site:

rating = soup.select_one(".rating").get_text(strip=True)
review_count = soup.select_one(".review-count").get_text(strip=True)

6) Handle anti-bot measures

Be careful with:

  • rate limiting
  • CAPTCHAs
  • login walls
  • session cookies

Use:

  • delays between requests
  • retries with backoff
  • caching
  • rotating only if permitted and ethical

7) Store the data

Save to:

  • CSV for simple analysis
  • JSON for nested review structures
  • a database for large-scale scraping

Example CSV output:

import csv

with open("ratings.csv", "w", newline="", encoding="utf-8") as f:
    writer = csv.DictWriter(f, fieldnames=["product", "rating", "review_count"])
    writer.writeheader()
    writer.writerow({"product": "Widget", "rating": 4.6, "review_count": 128})

8) A safer alternative: use APIs or data providers

Many ecommerce platforms offer:

  • official APIs
  • partner feeds
  • review export features

Examples:

  • Shopify apps / admin APIs
  • Amazon SP-API for authorized sellers
  • Trustpilot / Bazaarvoice APIs where applicable

If you want, I can give you:

  1. a Python script template for scraping ratings from a product page, or
  2. a site-specific approach if you tell me which ecommerce site you’re targeting.

Observation history

Unlock observation history

Create a free Obsurfable account to unlock historical responses, model comparisons, and deeper brand intelligence.

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, and Meta AI.