<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Practical Web Scraping]]></title><description><![CDATA[Practical Web Scraping]]></description><link>https://practical-scraping.hashnode.dev</link><image><url>https://cdn.hashnode.com/uploads/logos/6afb7f506d97d42178c1b404/44724789-fef4-4c6d-8afb-5931fd3cf276.png</url><title>Practical Web Scraping</title><link>https://practical-scraping.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Dec 2026 21:44:34 GMT</lastBuildDate><atom:link href="https://practical-scraping.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How to Scrape Zimmo Property Listings with Python]]></title><description><![CDATA[How to scrape Zimmo property listings with Python: collect zimmo.be sale and rent searches, then estimate gross rental yield by bedrooms.]]></description><link>https://practical-scraping.hashnode.dev/how-to-scrape-zimmo-property-listings-with-python</link><guid isPermaLink="true">https://practical-scraping.hashnode.dev/how-to-scrape-zimmo-property-listings-with-python</guid><category><![CDATA[Python]]></category><category><![CDATA[Real Estate]]></category><category><![CDATA[data analysis]]></category><category><![CDATA[web scraping]]></category><category><![CDATA[playwright]]></category><dc:creator><![CDATA[John Philip]]></dc:creator><pubDate>Fri, 04 Dec 2026 08:17:32 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6afb7f506d97d42178c1b404/dfab9acf-e324-4824-b309-00a391d96c54.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you're weighing a buy-to-let flat in Leuven, the first number you want is the gross rental yield: a year's rent divided by the purchase price. Zimmo, the Belgian property portal, lists both sides of that equation. This tutorial shows how to scrape Zimmo property listings with Python using <a href="https://github.com/2scraper/zimmo-scraper">2scraper/zimmo-scraper</a>, an MIT-licensed open-source scraper, and turn one sale search and one rent search into a yield estimate per bedroom count.</p>
<h2>How to scrape Zimmo property listings in six steps</h2>
<p>To scrape Zimmo property listings, run a Python browser scraper in a visible (headful) Chromium window on a Belgian or German residential connection, point it at a <a href="http://zimmo.be">zimmo.be</a> search-results URL, and it writes one row per listing with price, property type, living area, bedrooms, EPC label and address. A sidecar file and the exit code tell you whether the run completed.</p>
<ol>
<li>Clone the repository and create a Python 3.9–3.12 virtual environment.</li>
<li>Install the base and Playwright requirements, then Chromium.</li>
<li>Run a sale search with <code>--headful</code> and a few <code>--pages</code>.</li>
<li>Run the matching rent search the same way.</li>
<li>Check each run's exit code and <code>.meta.json</code>.</li>
<li>Compare median sale prices and rents with a short pandas script.</li>
</ol>
<h2>What a Zimmo search gives you</h2>
<table>
<thead>
<tr>
<th>Input</th>
<th>Example</th>
<th>What each row contains</th>
</tr>
</thead>
<tbody><tr>
<td>Dutch sale search</td>
<td><code>/nl/leuven-3000/te-koop/</code></td>
<td><code>price</code> in EUR, <code>property_type</code>, <code>surface_m2</code>, <code>bedrooms</code>, <code>epc_label</code>, <code>location</code>, <code>url</code>, <code>image_url</code></td>
</tr>
<tr>
<td>Dutch rent search</td>
<td><code>/nl/leuven-3000/te-huur/</code></td>
<td>The same columns, with <code>listing_type</code> set to rent</td>
</tr>
<tr>
<td>French sale or rent search</td>
<td><code>/fr/bruxelles-1000/a-vendre/</code>, <code>/a-louer/</code></td>
<td>The same columns from the French site</td>
</tr>
<tr>
<td>Anything that isn't a search-results page</td>
<td>a single listing URL</td>
<td>Refused with exit 2</td>
</tr>
</tbody></table>
<p>Every row has the same 19 columns in JSON and CSV. <code>listing_type</code> (sale or rent) and <code>property_type</code> (<code>huis</code>, <code>appartement</code>, <code>nieuwbouwproject</code>, <code>garage</code> and so on) come from the URL, so they're reliable. <code>sku</code> is Zimmo's listing code. <code>epc_label</code> is the energy grade, including Brussels grades such as E-.</p>
<p>Some columns are less useful than they look. <code>brand</code>, <code>original_price</code>, <code>discount_pct</code> and <code>epc_value</code> are always null. <code>surface_m2</code> is living area only. <code>price</code> is null for "price on request", and for a new-build project it's the cheapest unit's price, so it's a lower bound rather than a property price. There are no detail-page fields: the scraper reads search results only, so there's no agency, contact details, coordinates or listing date.</p>
<h2>Why Zimmo is fussy about who it serves</h2>
<p>Zimmo sits behind Cloudflare, and the README's access matrix from 2026-09-23 is blunt about it. The same Ghent sale URL was tried eight ways:</p>
<ul>
<li>curl from a datacentre got HTTP 403 "Just a moment…".</li>
<li>Chromium from a datacentre, headless or headful, got a Cloudflare challenge and exit 3.</li>
<li>Headless Chromium on a Belgian residential connection was also challenged.</li>
<li>Headful Chromium on a Belgian residential connection was served: 63 rows over 3 pages, exit 0. A German residential exit worked too.</li>
<li>The 2Captcha Scraping Browser API with a Belgian profile was served: 63 rows, 3 of 3 pages.</li>
</ul>
<p>Two conditions decide it: a residential IP and a visible browser. A US residential exit was refused in a later test, so the country matters too. That's why the quick start below uses <code>--headful</code>, and why a headless run from your cloud server will fail no matter how polite it is.</p>
<h2>Installing the Zimmo scraper</h2>
<p>The README supports Python 3.9 to 3.12, and CI tests 3.9 and 3.12. These are the commands from the <a href="https://github.com/2scraper/zimmo-scraper">zimmo-scraper repository on GitHub</a>:</p>
<pre><code class="language-bash">git clone https://github.com/2scraper/zimmo-scraper.git
cd zimmo-scraper
python3 -m venv .venv &amp;&amp; . .venv/bin/activate   # Python 3.9-3.12, see below for 3.13
pip install -r requirements.txt -r requirements-playwright.txt
playwright install chromium
cp .env.example .env   # on a server: set ZIMMO_PROXY to a residential proxy
</code></pre>
<p>On Python 3.13 the pinned <code>greenlet</code> has no wheel. The README's workaround is to install <code>greenlet pyee==11.1.0</code>, then <code>pip install --no-deps playwright==1.44.0</code>. Selenium and Puppeteer engines also exist, but Playwright and Puppeteer have conflicting <code>pyee</code> pins, so give each engine its own virtual environment.</p>
<p><code>.env</code> holds six optional settings: <code>TWOCAPTCHA_KEY</code>, <code>ZIMMO_URL</code>, <code>ZIMMO_CDP_ENDPOINT</code>, <code>ZIMMO_PROXY</code>, <code>ZIMMO_LOAD_MEDIA</code> and <code>ZIMMO_PROXY_BUDGET_MB</code>. Placeholders copied from the example file are treated as unset. To check your install without touching <a href="http://zimmo.be">zimmo.be</a>, run <code>python3 smoke_test.py</code>: it needs no network and no browser.</p>
<h2>Collecting the sale and rent searches</h2>
<p>From a home connection in Belgium or Germany, with a screen, run the two searches one after the other. If you're elsewhere, the README's tests refused a US residential exit, so use a Belgian proxy or the Scraping Browser API described below:</p>
<pre><code class="language-bash">python3 playwright_scraper.py --url "https://www.zimmo.be/nl/leuven-3000/te-koop/" \
  --pages 3 --headful --delay 5 --format json --out leuven_sale
python3 playwright_scraper.py --url "https://www.zimmo.be/nl/leuven-3000/te-huur/" \
  --pages 3 --headful --delay 5 --format json --out leuven_rent
</code></pre>
<p><code>--out</code> is a file prefix, so the first run writes <code>leuven_sale.json</code> and <code>leuven_sale.meta.json</code>. Pass the URL without a <code>page</code> parameter; the scraper adds it, and a URL that already has one is exit 2. <code>--delay 5</code> waits five seconds after each page, which keeps the run polite and costs you nothing.</p>
<p>On a server with no display, the README wraps the same command in <code>xvfb-run -a</code>. That gives Chromium a virtual screen, but it doesn't fix the IP: the README's own 2026-11-17 check of the quick start from a datacentre address ended in a Cloudflare challenge, exit 3, with nothing written. On a server you need <code>ZIMMO_PROXY</code> pointing at a residential proxy, or the Scraping Browser API described below.</p>
<h2>Reading the run before the data</h2>
<p>Each run's <code>.meta.json</code> records <code>status</code> (<code>complete</code>, <code>partial</code> or <code>empty</code>), <code>stop_reason</code>, <code>failed_pages</code>, <code>parser_failed_pages</code>, <code>selection</code> (the search URL without its page parameter) and <code>listing_exhausted</code>, which says whether the run read the search to its end. On the Dutch site, asking for more pages than exist is fine: the run stops when Zimmo says "We vonden helaas geen resultaten" and is marked complete with <code>listing_exhausted: true</code>. On the French site the "no results" wording isn't known yet, so overshooting ends the run partial.</p>
<p>The exit codes:</p>
<ul>
<li><code>0</code>: complete</li>
<li><code>6</code>: partial; rows written, check <code>stop_reason</code> and <code>failed_pages</code></li>
<li><code>3</code>: blocked, usually by Cloudflare</li>
<li><code>4</code>: zero listings (without <code>--allow-empty</code>)</li>
<li><code>5</code>: content never obtained, including proxy failures such as <code>proxy_auth_failed</code> (407) or <code>proxy_balance_exhausted</code> (402)</li>
<li><code>2</code>: bad usage</li>
<li><code>1</code>: crash</li>
<li><code>130</code>: stopped with Ctrl-C before any row</li>
</ul>
<p>Don't run the yield script on a run that exited 3, 4 or 5: there's nothing new in the file, and an old file from a previous run may still be sitting there.</p>
<h2>Where 2Captcha fits for Zimmo</h2>
<p>The useful 2Captcha piece here isn't CAPTCHA solving. It's the remote browser. The <a href="https://2captcha.com/?utm_source=hashnode&amp;utm_medium=article&amp;utm_campaign=zimmo-scraper">2Captcha</a> Scraping Browser API gives you a browser with a Belgian exit, and in the access matrix it was served without a home connection or a proxy of your own. Put the endpoint in <code>ZIMMO_CDP_ENDPOINT</code> (or pass <code>--cdp-endpoint</code>) in the README's format:</p>
<pre><code class="language-plaintext">ws://{login}-zone-scraping_browser-country-be-pid-{profileId}:{password}@cb.2captcha.com:9222
</code></pre>
<p>Reuse the same <code>pid</code>: it keeps the profile's cookies and the trust Cloudflare has already given it. Since v1.2.1 the scraper opens one connection per run, because reconnecting used to fail with HTTP 500. <code>--cdp-endpoint</code> can't be combined with <code>--proxy</code> or with <code>--concurrency</code> above 1, and an HTTP 401 <code>deny_no_user</code> on connect means fetching fresh credentials. Selenium can't authenticate to a CDP endpoint at all.</p>
<p>The same <code>TWOCAPTCHA_KEY</code> also enables CAPTCHA solving with <code>--solve-captcha when-blocked</code> (the default), at most one paid solve per page. Be realistic about it: the README says the solver "was not exercised" in its measured runs, and solving the Cloudflare interstitial "was not tested". The 2Captcha Scraper API is wired in too, but it returned "0 resultaten" for Ghent twice on 2026-10-28 while the Browser API read 63 listings from the same URL that day. If you're in Belgium or Germany, I'd start with your home connection. Anywhere else, or on a server, the Browser API is the simpler route.</p>
<p>If you use a residential proxy instead, the scraper checks it first (one CONNECT and a <code>HEAD /robots.txt</code>) and caps traffic with <code>--proxy-budget-mb</code>, 10 MB by default. The README measured about 2.6 MB per page through a residential exit, so three pages fit with room to spare.</p>
<h2>One row from the sample file</h2>
<p>The repository's <code>sample_output.json</code> holds one Ghent sale page from 2026-09-23. Here's an apartment from it, without <code>scraped_at</code> and the long <code>image_url</code>:</p>
<pre><code class="language-json">{
  "source": "zimmo.be",
  "url": "https://www.zimmo.be/nl/gent-9000/te-koop/appartement/LRZKI",
  "sku": "LRZKI",
  "title": "Appartement te koop",
  "brand": null,
  "price": 355000.0,
  "currency": "EUR",
  "original_price": null,
  "discount_pct": null,
  "category": "gent-koop",
  "listing_type": "sale",
  "property_type": "appartement",
  "location": "Martelaarslaan 287 9000 Gent",
  "surface_m2": 92.0,
  "bedrooms": 2,
  "epc_label": null,
  "epc_value": null
}
</code></pre>
<p><code>scraped_at</code>, left out above, is when the run happened (2026-09-23 for the whole sample), not when the listing went up. <code>location</code> is the address exactly as the search tile shows it, which matters for the legal note further down.</p>
<h2>Estimating gross yield with pandas</h2>
<p>This script keeps apartments with a price and a bedroom count from both runs, then compares the median sale price with the median rent for each bedroom count. Install pandas first, since it isn't one of the scraper's requirements:</p>
<pre><code class="language-bash">pip install pandas
</code></pre>
<p>Save it as <code>yield.py</code>:</p>
<pre><code class="language-python">import sys

import pandas as pd

sale_file = sys.argv[1] if len(sys.argv) &gt; 1 else "leuven_sale.json"
rent_file = sys.argv[2] if len(sys.argv) &gt; 2 else "leuven_rent.json"


def flats(path):
    df = pd.read_json(path, dtype={"sku": str})
    df = df[(df["property_type"] == "appartement") &amp; (df["currency"] == "EUR")]
    return df.dropna(subset=["price", "bedrooms"])


sale, rent = flats(sale_file), flats(rent_file)
summary = pd.DataFrame({
    "for_sale": sale.groupby("bedrooms")["sku"].count(),
    "median_price": sale.groupby("bedrooms")["price"].median(),
    "for_rent": rent.groupby("bedrooms")["sku"].count(),
    "median_rent": rent.groupby("bedrooms")["price"].median(),
}).dropna()
summary["gross_yield_pct"] = (summary["median_rent"] * 12 / summary["median_price"] * 100).round(2)
summary.index = summary.index.astype(int)
summary[["for_sale", "for_rent"]] = summary[["for_sale", "for_rent"]].astype(int)

print(summary.to_string())
summary.to_csv("leuven_yield.csv")
</code></pre>
<p>Run it with <code>python3 yield.py leuven_sale.json leuven_rent.json</code>. It writes <code>leuven_yield.csv</code> with one row per bedroom count that appears in both searches.</p>
<p>Three things to watch. First, the README doesn't say what period a rent <code>price</code> covers. The script assumes a monthly rent, so open a few rent rows on <a href="http://zimmo.be">zimmo.be</a> before you trust the yield. Second, keep an eye on <code>for_sale</code> and <code>for_rent</code>: with three pages each, some bedroom counts will rest on two or three listings, and a median of two is barely a number. Third, gross yield ignores costs, vacancy and taxes, and it's built from asking prices and asking rents rather than closed deals, so treat it as a first filter, not an investment case.</p>
<p>The bundled sample only has sale listings, so it can't produce a yield on its own. Its six apartments do give the sale side: the median asking price is €360,000 for the four two-bedroom flats and €432,000 for the two three-bedroom ones.</p>
<h2>Limits worth knowing</h2>
<ul>
<li>Search-results pages only. No detail pages, so no full descriptions, agency details or coordinates.</li>
<li>Only a headful browser on a residential (Belgian or German) connection, or the Scraping Browser API, was served in the README's tests.</li>
<li>New-build project prices are the cheapest unit, a lower bound.</li>
<li>On the French site, running past the last page ends as partial (exit 6).</li>
<li>The weekly canary was last green on 2026-10-21; later runs failed at the proxy pre-check with HTTP 407, before reaching <a href="http://zimmo.be">zimmo.be</a>.</li>
<li>The Docker image runs headless, so on its own it will be challenged; use it with <code>--cdp-endpoint</code>.</li>
</ul>
<h2>Scraping Zimmo legally and politely</h2>
<p>Collect public listing data only, read Zimmo's terms of service and robots.txt first, and keep the request rate low with <code>--delay</code>. The scraper reads public search pages and doesn't log in. Property listings are closer to personal data than product listings: the <code>location</code> column can be a private seller's home address, so under the GDPR you need a lawful basis to store it. For a yield analysis you don't need it at all, so drop or truncate <code>location</code> to the postcode before you save anything long-term. Listing photos and texts can also be protected by copyright.</p>
<h2>FAQ</h2>
<h3>Does Zimmo have a public API?</h3>
<p>Not one this scraper uses. It reads the same search pages a visitor sees, rendered in a real browser, because Zimmo's listing data isn't in any structured block on the page.</p>
<h3>Why does Zimmo block headless browsers and servers?</h3>
<p>Cloudflare. In the README's tests, every datacentre attempt and every headless attempt was challenged, while a headful browser on a Belgian or German residential connection was served.</p>
<h3>How do I scrape Zimmo from a server?</h3>
<p>Use <code>xvfb-run -a</code> for a virtual display plus either a residential proxy in <code>ZIMMO_PROXY</code> or the 2Captcha Scraping Browser API in <code>ZIMMO_CDP_ENDPOINT</code>. A server's own IP gets the Cloudflare challenge.</p>
<h3>Can I scrape Zimmo rental listings?</h3>
<p>Yes. Use a <code>te-huur</code> URL on the Dutch site or <code>a-louer</code> on the French site; <code>listing_type</code> is set to rent. Check the period a rent price covers before comparing it with sale prices.</p>
<h3>Can I track Zimmo prices over time?</h3>
<p>Yes. Run the same search on two dates and compare with <code>python3 diff_runs.py --old run1.json --new run2.json</code>. It refuses incomplete runs and different searches, and a listing missing from a capped run is reported as having left the selection, not as removed.</p>
<h3>How much does it cost to scrape Zimmo?</h3>
<p>A run from your own residential connection in Belgium or Germany costs nothing. The Scraping Browser API, residential proxies and CAPTCHA solves are paid 2Captcha services, so check current prices, and use <code>--proxy-budget-mb</code> to cap proxy traffic.</p>
<h2>Where to go next</h2>
<p>Swap Leuven for your own city, or add a second city's searches and compare yields side by side. The code, the access matrix and every measurement quoted here are in the <a href="https://github.com/2scraper/zimmo-scraper">zimmo-scraper repository on GitHub</a>, and there are details and more scrapers on the <a href="https://2scraper.com/scrapers/zimmo-scraper/">Zimmo Scraper page at 2scraper.com</a>. 2Captcha's guide How to scrape Zimmo is the full reference of all options. If you need to run from a server rather than your laptop, that's the point to set up a 2Captcha key and a Belgian Scraping Browser profile.</p>
]]></content:encoded></item><item><title><![CDATA[How to Scrape Rakuten Products with Python]]></title><description><![CDATA[How to scrape Rakuten products with Python: collect Ichiba prices, subscription prices, points and shops, then rank the best subscription deals.]]></description><link>https://practical-scraping.hashnode.dev/how-to-scrape-rakuten-products-with-python</link><guid isPermaLink="true">https://practical-scraping.hashnode.dev/how-to-scrape-rakuten-products-with-python</guid><category><![CDATA[Python]]></category><category><![CDATA[web scraping]]></category><category><![CDATA[playwright]]></category><category><![CDATA[Tutorial]]></category><category><![CDATA[data analysis]]></category><dc:creator><![CDATA[John Philip]]></dc:creator><pubDate>Thu, 03 Dec 2026 08:24:48 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6afb7f506d97d42178c1b404/e8a5f404-1ffe-46b8-b279-b4b8afa0adec.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Rakuten Ichiba shops often list two prices for the same tea or coffee: a one-off price and a lower subscription price for regular deliveries. This tutorial shows how to scrape Rakuten products with Python using <a href="https://github.com/2scraper/rakuten-scraper">2scraper/rakuten-scraper</a>, an MIT-licensed open-source scraper, and then rank a search by how much a subscription actually saves. By the end you'll have a JSON file of Japanese green tea listings and a CSV of the best subscription deals, with points kept in a separate column.</p>
<h2>How to scrape Rakuten products, step by step</h2>
<p>To scrape Rakuten products, run a Python browser scraper against a <a href="http://search.rakuten.co.jp">search.rakuten.co.jp</a> search URL. It reads the JSON payload the page is built from and writes one row per product, with price, subscription price, Rakuten points, shop, rating and shipping. No key, proxy or account is needed for a first run, and each run reports whether it completed.</p>
<ol>
<li>Clone the repository and create a Python 3.9+ virtual environment.</li>
<li>Install the base and Playwright requirements, then Chromium.</li>
<li>Run one search URL with <code>--pages 2</code>.</li>
<li>Check the exit code and the <code>.meta.json</code> sidecar.</li>
<li>Open a single product with <code>--mode product</code> if you need variants.</li>
<li>Rank subscription savings with a short pandas script.</li>
</ol>
<h2>What the scraper returns for each input</h2>
<table>
<thead>
<tr>
<th>Input URL</th>
<th>Mode</th>
<th>What you get</th>
</tr>
</thead>
<tbody><tr>
<td><code>search.rakuten.co.jp/search/mall/{keyword}/</code></td>
<td><code>listing</code></td>
<td>45 products per page: <code>price</code>, <code>price_max</code>, <code>subscription_price</code>, <code>points</code>, <code>point_rate</code>, <code>rating</code>, <code>review_count</code>, <code>shop_*</code>, shipping fields</td>
</tr>
<tr>
<td><code>search.rakuten.co.jp/search/mall/-/{genreId}/</code> or <code>www.rakuten.co.jp/category/{genreId}/</code></td>
<td><code>listing</code></td>
<td>The same fields for a whole genre</td>
</tr>
<tr>
<td><code>item.rakuten.co.jp/{shop}/{code}/</code></td>
<td><code>product</code></td>
<td>One product with per-variant prices and a variant count</td>
</tr>
<tr>
<td><code>www.rakuten.co.jp/{shopCode}/</code></td>
<td>refused</td>
<td>Storefronts have no product payload, and the scraper says so</td>
</tr>
</tbody></table>
<p>Every row is in JPY and carries a <code>sku</code> in the form <code>{shopCode}:{manageNumber}</code>, which is the same on listing and product routes. That makes it a stable key when you go from a search to a product page.</p>
<p>Three fields need care. <code>in_stock</code> was true on all 405 listing rows in the README's measurement, so it isn't much of a filter on listings. <code>original_price</code> and <code>discount_pct</code> are null on every listing row, because a verified was-price only exists on item pages. And <code>points</code> is a discount Rakuten pays back as points, which never touches <code>price</code>.</p>
<h2>Why Rakuten blocks some clients and not others</h2>
<p>Rakuten sits behind Akamai, and the README's measurements show it doesn't simply block datacenter IPs. It refuses clients whose claimed identity and TLS fingerprint disagree. In the 2026-09-21 test from a Hetzner server in Helsinki, plain curl with its own user agent got a full 919 KB page with 45 products, while curl pretending to be Chrome got a 42–43 byte "Reference #…" page. Headless and headful Chromium both got the products.</p>
<p>The refusal arrives as HTTP 200, which is what makes it awkward: a naive scraper sees success and an empty page. The scraper tells them apart by counting <code>r10s.jp</code> asset hosts, which appear 90 to 343 times on a served page and 0 or 1 times on a refusal.</p>
<p>There's also a hard cap. Rakuten serves at most 150 pages of 45, so 6,750 results per query, however many products match. The README's example query matched 3,053,682 products, so even a full run is a 0.2% sample. Narrow searches beat broad ones.</p>
<h2>Installing the Rakuten scraper</h2>
<p>Python 3.9 or newer is required; CI runs the offline suite on 3.9 and 3.13. Clone the <a href="https://github.com/2scraper/rakuten-scraper">rakuten-scraper repository on GitHub</a>, then follow the README's quick start:</p>
<pre><code class="language-bash">git clone https://github.com/2scraper/rakuten-scraper.git
cd rakuten-scraper
python3 -m venv .venv &amp;&amp; . .venv/bin/activate
pip install -r requirements.txt -r requirements-playwright.txt
playwright install chromium
</code></pre>
<p>Selenium and Puppeteer engines are there too (<code>requirements-selenium.txt</code>, <code>requirements-puppeteer.txt</code>), but Playwright is the recommended one, and the README notes pyppeteer is effectively unmaintained. Before going online, <code>python3 smoke_test.py</code> runs the offline tests with no network.</p>
<p>You don't need a <code>.env</code> file to start. The optional one (copy <code>.env.example</code>) takes <code>TWOCAPTCHA_KEY</code>, <code>RAKUTEN_CDP_ENDPOINT</code>, <code>RAKUTEN_PROXY</code> and <code>RAKUTEN_URL</code>. Keys belong in that file, never on the command line, and <code>python3 env_config.py</code> shows what was loaded without printing secrets.</p>
<h2>First run: a green tea search</h2>
<pre><code class="language-bash">python3 playwright_scraper.py \
  --url "https://search.rakuten.co.jp/search/mall/緑茶/" --pages 2 --out greentea
echo $?
</code></pre>
<p>That's 緑茶, green tea, as the keyword. The run writes the products to <code>greentea.json</code> along with a <code>.meta.json</code> sidecar describing the run: <code>status</code> (<code>complete</code>, <code>partial</code> or <code>failed</code>), <code>stop_reason</code> (such as <code>end_of_listing</code> or <code>throttled</code>), <code>pages_failed</code>, <code>total_results</code> and <code>reachable_max</code>. Add <code>--format csv</code> when you want a CSV for a spreadsheet.</p>
<p>A run that finds no products writes nothing unless you pass <code>--allow-empty</code>, so an old file can outlive a failed run. The exit code tells you which case you're in:</p>
<ul>
<li><code>0</code>: products written</li>
<li><code>6</code>: partial run; check <code>stop_reason</code> and <code>pages_failed</code></li>
<li><code>3</code>: blocked before parsing</li>
<li><code>4</code>: a page was served but had zero products</li>
<li><code>5</code>: content never obtained, for example a page that stayed throttled after every wait</li>
<li><code>2</code>: bad usage</li>
<li><code>1</code>: crash</li>
</ul>
<p>Don't be surprised if <code>total_results</code> is in the hundreds of thousands while you got 90 rows. You asked for two pages, and <code>reachable_max</code> tells you how far the 6,750 cap would let you go.</p>
<p><code>--locale en</code> adds <code>?lang=en</code>, but it only translates Rakuten's navigation. Titles, shop names and tags stay in Japanese, so plan for Japanese text in your data.</p>
<h2>From search result to product page</h2>
<p>A listing row gives you <code>price</code> and, when the product has options, a <code>price_max</code> with <code>has_price_range: true</code>. To see the individual options, take the row's <code>url</code> and run it in product mode. This is the README's own product example:</p>
<pre><code class="language-bash">python3 playwright_scraper.py \
  --url "https://item.rakuten.co.jp/sawaicoffee-tea/solandluna/" --mode product --out tea_item
</code></pre>
<p>Product mode reads the item page's own app data (<code>item-page-app-data</code>) and returns per-variant prices and a variant count. It's also the only place a verified was-price can appear, so if you need real discounts rather than campaign titles, product pages are where to look. Item pages are EUC-JP encoded while listings are UTF-8; the scraper handles both, but keep it in mind if you ever fetch pages yourself.</p>
<h2>Throttling, Akamai and where 2Captcha comes in</h2>
<p>There's no CAPTCHA on these routes today. The README reports zero CAPTCHA vendor markers across 13 captures. What you'll actually hit is throttling and the occasional Akamai refusal.</p>
<p>HTTP 503 is a throttle, not a block. The scraper waits 6 seconds, then 15, then 30, and only gives up on that page after the last wait. HTTP 403 and the tiny "Reference #" page count as blocks. Spacing pages out with <code>--delay 4</code> is the cheapest fix for throttling, and it costs nothing.</p>
<p>For long runs, a key from <a href="https://2captcha.com/?utm_source=hashnode&amp;utm_medium=article&amp;utm_campaign=rakuten-scraper">2Captcha</a> covers four separately billed services the scraper supports:</p>
<ul>
<li>Japanese residential proxies through <code>RAKUTEN_PROXY</code> (the country comes from <code>-region-jp</code> in the login), with <code>--proxy-rotate per-page</code> to relaunch the browser on a new IP for each page</li>
<li>the Scraping Browser API, a remote browser you connect to with <code>--cdp-endpoint</code> or <code>RAKUTEN_CDP_ENDPOINT</code></li>
<li>browser fingerprints with <code>--fingerprint</code></li>
<li>CAPTCHA solving, which is wired in for reCAPTCHA v2/v3 but has nothing to solve on Rakuten right now</li>
</ul>
<p>A few combinations are refused on purpose. With <code>--cdp-endpoint</code>, <code>--concurrency</code> above 1 or a typed <code>--proxy</code> is exit 2, because each browser profile allows one live connection. Selenium can't use a credentialed CDP endpoint at all.</p>
<p>My take: for a green tea search of a few pages, you won't need any of it. The README's own 2026-11-17 run of the quick start returned 45 rows, complete, exit 0, with no credentials. Reach for proxies when you start running many searches in a row and seeing <code>throttled</code> in <code>stop_reason</code>.</p>
<h2>One listing row from the sample file</h2>
<p>Selected fields from a row in the repository's <code>sample_output.json</code>, collected on 2026-09-21 from a coffee search (title, URLs and tags left out):</p>
<pre><code class="language-json">{
  "source": "rakuten.co.jp",
  "sku": "sawaicoffee-tea:sol150",
  "price": 7998.0,
  "price_max": null,
  "has_price_range": false,
  "subscription_price": 7198.0,
  "currency": "JPY",
  "points": 148,
  "point_rate": 2,
  "rating": 4.65,
  "review_count": 1375,
  "shop_code": "sawaicoffee-tea",
  "shop_name": "澤井珈琲Beans&amp;Leaf",
  "is_official_shop": false,
  "brand": "澤井珈琲",
  "category": "コーヒー豆",
  "genre_id": 201402,
  "genre_rank": null,
  "original_price": null,
  "discount_pct": null,
  "in_stock": true,
  "price_source": "state",
  "shipping_fee": 0.0,
  "free_shipping": true,
  "is_39shop": true,
  "variants": null,
  "scraped_at": "2026-09-21T09:22:22.033563+00:00"
}
</code></pre>
<p>Each row has 42 columns in total. <code>rating</code> and <code>review_count</code> are null together when a product has no reviews, since Rakuten reports those as a score of 0. <code>genre_rank</code> is the item's place in Rakuten's genre ranking, not its position in your search.</p>
<h2>Ranking subscription savings with pandas</h2>
<p>Subscription prices aren't on every product: in the README's 405-row measurement, 54 rows had one. The script below keeps the single-price ones, works out the saving against the one-off price, and writes the best deals to CSV. It also summarises by shop. Install pandas first, as it isn't one of the scraper's requirements:</p>
<pre><code class="language-bash">pip install pandas
</code></pre>
<p>Save this as <code>subscriptions.py</code>:</p>
<pre><code class="language-python">import sys

import pandas as pd

path = sys.argv[1] if len(sys.argv) &gt; 1 else "greentea.json"
df = pd.read_json(path, dtype={"sku": str, "shop_code": str})
total = len(df)

subs = df[(df["currency"] == "JPY") &amp; df["subscription_price"].notna()
          &amp; (df["has_price_range"] == False)].copy()
subs["saving_yen"] = subs["price"] - subs["subscription_price"]
subs["saving_pct"] = (subs["saving_yen"] / subs["price"] * 100).round(1)

cols = ["sku", "shop_name", "price", "subscription_price", "saving_pct",
        "points", "rating", "review_count"]
best = subs.sort_values("saving_pct", ascending=False)[cols]
best.to_csv("subscription_deals.csv", index=False, encoding="utf-8-sig")

by_shop = subs.groupby("shop_name").agg(
    items=("sku", "count"), median_saving_pct=("saving_pct", "median"))
print(f"{len(subs)} of {total} products have one price and a subscription price")
print(by_shop.sort_values("median_saving_pct", ascending=False).to_string())
</code></pre>
<p>Run it with <code>python3 subscriptions.py greentea.json</code>. Products with <code>has_price_range: true</code> are left out, because their <code>price</code> and <code>subscription_price</code> may come from different variants, which would make the saving percentage meaningless. The <code>utf-8-sig</code> encoding is there so Excel opens the Japanese shop names correctly instead of showing garbled text.</p>
<p>Points stay a separate column on purpose. They're paid back later and depend on the shopper's campaigns, so mixing them into the saving would hide what the subscription itself is worth.</p>
<p>On the repository sample, six of the nine coffee rows have a subscription price, but three of those have a price range across variants and are filtered out. The remaining three, all from the same shop, each save 10.0%.</p>
<h2>Limits to plan around</h2>
<ul>
<li>Only <a href="http://rakuten.co.jp">rakuten.co.jp</a> (Rakuten Ichiba) is supported, and prices are JPY.</li>
<li>Each query tops out at 6,750 results, 150 pages of 45.</li>
<li>Listing rows have no was-price; <code>original_price</code> is null until you open the item page.</li>
<li>Storefront pages and <a href="http://ranking.rakuten.co.jp">ranking.rakuten.co.jp</a> aren't supported.</li>
<li>Sponsored placements mean the 45 rows per page come from a payload of about 52 entries, and the count varies between fetches.</li>
<li>The engines aren't guaranteed to produce identical files. In a 2026-10-29 test on a filtered search, Playwright and Selenium shared 44 of 45 SKUs per page.</li>
</ul>
<h2>Legal and polite scraping</h2>
<p>Collect public product data only. Read Rakuten's terms of service and robots.txt before scraping, use a moderate <code>--delay</code>, and stop when Rakuten starts refusing or throttling every page. Nothing here logs in or touches customer accounts. Shop names are business data, but if you extend this to reviews or anything that identifies a person, GDPR and Japan's APPI apply.</p>
<h2>FAQ</h2>
<h3>Does Rakuten have an API for product data?</h3>
<p>Yes, Rakuten offers an official Ichiba Item Search API through Rakuten Web Service, with its own quotas and result limits. This scraper doesn't use it; it reads the same JSON payload the Ichiba pages are built from, so you get fields such as <code>subscription_price</code> and shop flags as shown on the site.</p>
<h3>Do I need a proxy or CAPTCHA solver to scrape Rakuten?</h3>
<p>Not for small runs. The README's quick start works with no key, proxy or account. Japanese proxies and the Scraping Browser API help with long or repeated runs that start getting throttled, and there's currently no CAPTCHA to solve.</p>
<h3>How do I scrape Rakuten without getting blocked?</h3>
<p>Use a real browser engine rather than a faked user agent, add <code>--delay</code> between pages, and keep queries narrow. A 503 means slow down; the scraper backs off automatically before failing the page.</p>
<h3>Can I build a Rakuten price tracker in Python?</h3>
<p>Yes. Save two runs and compare them with <code>python3 diff_runs.py --old monday.json --new tuesday.json --fail-on-change</code>. It joins on <code>sku</code>, reports added, removed and changed products, tracks <code>points</code> and <code>point_rate</code>, and refuses to compare a partial run with a complete one.</p>
<h3>Can I scrape Rakuten reviews?</h3>
<p>Only as numbers. Each row has <code>rating</code> and <code>review_count</code>; review text isn't collected.</p>
<h3>How do I export Rakuten data to CSV?</h3>
<p>Add <code>--format csv</code> to the run. String cells are escaped so a spreadsheet won't treat them as formulas, and the sidecar counts them in <code>csv_cells_escaped</code>.</p>
<h2>Where to go next</h2>
<p>Try the same script on a genre URL instead of a keyword, or rerun it weekly to see whether shops change their subscription pricing. The code, the measurements behind every number here and the troubleshooting notes are in the <a href="https://github.com/2scraper/rakuten-scraper">rakuten-scraper repository on GitHub</a>, and there are details and more scrapers on the <a href="https://2scraper.com/scrapers/rakuten-scraper/">Rakuten Scraper page at 2scraper.com</a>. 2Captcha's guide How to scrape Rakuten is the full reference of all options. When your runs grow past a few pages and start coming back throttled, that's the point to add a 2Captcha key and a Japanese proxy.</p>
]]></content:encoded></item><item><title><![CDATA[How to Scrape SHEIN Products: Prices, Discounts, Stock.]]></title><description><![CDATA[Say you're thinking about selling crochet tops and want to know how SHEIN prices them: how many sellers there are, what a typical price is, and how often…]]></description><link>https://practical-scraping.hashnode.dev/how-to-scrape-shein-products-prices-discounts-stock</link><guid isPermaLink="true">https://practical-scraping.hashnode.dev/how-to-scrape-shein-products-prices-discounts-stock</guid><dc:creator><![CDATA[John Philip]]></dc:creator><pubDate>Mon, 16 Nov 2026 22:35:58 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6afb7f506d97d42178c1b404/bb33df36-2356-4bce-8978-3f512df6fd31.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Say you're thinking about selling crochet tops and want to know how SHEIN prices them: how many sellers there are, what a typical price is, and how often items are on discount. This tutorial shows how to scrape SHEIN products with Python using <a href="https://github.com/2scraper/shein-scraper">2scraper/shein-scraper</a>, an MIT-licensed open-source scraper, and turn one search into a small per-seller table. In about 15 minutes you'll have a JSON file of products and a CSV that summarises the niche.</p>
<h2>How to scrape SHEIN products: the short version</h2>
<p>To scrape SHEIN products, run an open-source browser scraper that loads the search page, reads the product data SHEIN embeds in it, and writes each product as one JSON or CSV row. Each row includes price, currency, discount, rating, review count and stock flag. A run metadata file tells you whether the run completed.</p>
<ol>
<li>Clone 2scraper/shein-scraper and create a Python 3.9+ virtual environment.</li>
<li>Install the Playwright requirements and Chromium.</li>
<li>Copy <code>.env.example</code> to <code>.env</code> and add keys only if you use them.</li>
<li>Run one search with <code>--query</code> and <code>--max-results 20</code>.</li>
<li>Check the exit code and the <code>.meta.json</code> file next to the output.</li>
<li>Load the JSON into pandas and group it by seller.</li>
</ol>
<h2>What you get from each type of input</h2>
<table>
<thead>
<tr>
<th>Input</th>
<th>Where the scraper reads it</th>
<th>What you get</th>
</tr>
</thead>
<tbody><tr>
<td><code>--query "crochet top"</code></td>
<td>Search listing, from <code>window.gbRawData</code></td>
<td>One row per product: <code>price</code>, <code>original_price</code>, <code>discount_pct</code>, <code>rating</code>, <code>review_count</code>, <code>in_stock</code></td>
</tr>
<tr>
<td><code>--category "Women Jeans-c-1934.html"</code></td>
<td>Category listing, same embedded data</td>
<td>The same fields for a whole category</td>
</tr>
<tr>
<td><code>--url</code> with a product page</td>
<td><a href="http://schema.org">schema.org</a> JSON-LD on the page</td>
<td>Identity and price; for variants with different prices, the lowest one</td>
</tr>
<tr>
<td>Any of the above</td>
<td>Every row</td>
<td><code>currency</code> (USD on <a href="http://us.shein.com">us.shein.com</a>) and <code>scraped_at</code></td>
</tr>
</tbody></table>
<p>Variants are the part to read carefully. <code>sku</code> is SHEIN's <code>goods_id</code>, and it's the same across all colours and sizes of a product. So you get one row per product, not per variant, and <code>in_stock</code> is SHEIN's product-level flag. On a product page where variants are priced differently, <code>price_source</code> is <code>json_ld_min_variant</code>: the price is the cheapest variant, not every variant.</p>
<h2>Why SHEIN is harder to scrape than it looks</h2>
<p>A plain HTTP request won't get you far, for three reasons the README spells out. The product grid is JavaScript-rendered, so the data lives in a script object rather than in the HTML you'd parse. Listings load as you scroll, and whether scrolling actually loads products beyond the first ~20 hasn't been confirmed. And suspicious traffic gets sent to a risk gateway at <code>/risk/challenge</code> or <code>/risk/action/limit</code>, which the scraper has to recognise and handle.</p>
<h2>Setup</h2>
<p>You need Python 3.9 or newer. The repository supports three engines (Playwright, Selenium, Puppeteer), and their dependencies conflict, so install one per virtual environment. Playwright is the recommended one:</p>
<pre><code class="language-bash">git clone https://github.com/2scraper/shein-scraper.git
cd shein-scraper
python3 -m venv .venv &amp;&amp; source .venv/bin/activate
pip install -r requirements-playwright.txt
playwright install chromium
cp .env.example .env        # add your keys here, never on the command line
</code></pre>
<p><code>.env</code> has four variables:</p>
<ul>
<li><code>TWOCAPTCHA_KEY</code>: one 2Captcha key, shared by CAPTCHA solving, the Scraping Browser API and the Fingerprint API</li>
<li><code>SHEIN_PROXY</code>: a proxy for the local engines</li>
<li><code>SHEIN_CDP_ENDPOINT</code>: a remote browser endpoint</li>
<li><code>SHEIN_URL</code>: a default for <code>--url</code></li>
</ul>
<p>None of them is needed for a first try. According to <code>.env.example</code>, the default is a plain local headless Chromium with no proxy and no CAPTCHA key. That's fine for testing. For regular use the README recommends adding the key, because SHEIN will start challenging a bare local browser.</p>
<p>Settings are read in this order: CLI flag, then exported environment variable, then <code>.env</code>, then the flag's default.</p>
<h2>First run: one search, two files</h2>
<pre><code class="language-bash">python3 playwright_scraper.py --query "crochet top" --max-results 20 --out crochet_tops.json
echo $?
</code></pre>
<p>If rows were collected, you get two files: <code>crochet_tops.json</code> with the products and <code>crochet_tops.json.meta.json</code>, which records the run's status, <code>stop_reason</code>, product count, <code>total_results</code>, whether <code>--max-results</code> capped the run, solves spent and a hash of the output. A run that collects nothing writes neither file.</p>
<p>For CSV straight away, add <code>--format csv</code> and change the extension:</p>
<pre><code class="language-bash">python3 playwright_scraper.py --query "crochet top" --max-results 20 --format csv --out crochet_tops.csv
</code></pre>
<p>Don't skip <code>echo $?</code>. The exit code is the quickest way to know what kind of data you have:</p>
<ul>
<li><code>0</code>: complete</li>
<li><code>6</code>: partial, rows written; <code>stop_reason</code> is one of <code>blocked</code>, <code>rate_limited</code>, <code>remote_api_error</code>, <code>failed_pages</code>, <code>rejected_rows</code></li>
<li><code>3</code>: blocked or rate-limited, no rows</li>
<li><code>4</code>: the page loaded but had no products</li>
<li><code>5</code>: content not obtained; <code>stop_reason: parser_found_nothing</code> usually means SHEIN changed its layout</li>
<li><code>2</code>: bad usage</li>
<li><code>1</code>: crash</li>
</ul>
<p>A run is also marked partial when it collects fewer products than SHEIN reports for the search, which is likely for a niche bigger than one screen.</p>
<h2>From search to product page</h2>
<p>The listing gives you a good overview. When you want to look at one product closely, pass its <code>product_url</code> back to the scraper with <code>--url</code>. This picks the most-reviewed product from the search and scrapes its page:</p>
<pre><code class="language-python">import json
import subprocess
import sys

with open("crochet_tops.json", encoding="utf-8") as f:
    rows = json.load(f)

reviewed = [r for r in rows if r.get("review_count")]
top = max(reviewed, key=lambda r: r["review_count"])
print(f"Scraping product page for SKU {top['sku']}")

subprocess.run([sys.executable, "playwright_scraper.py",
                "--url", top["product_url"], "--out", "top_product.json"])
</code></pre>
<p>Expect fewer fields on the product page. JSON-LD carries the product's identity and price, and other fields may be missing. That's also where <code>json_ld_min_variant</code> shows up, so a product-page price can look lower than the listing price for the same SKU. Check <code>price_source</code> before you call it a price drop.</p>
<h2>How the scraper works</h2>
<p>The Playwright engine opens the search in Chromium (local, or a remote browser over <code>--cdp-endpoint</code>). It reads <code>window.gbRawData</code>, then scrolls: up to <code>--max-scrolls</code> 20 times, with <code>--scroll-delay</code> 1.5s, stopping after <code>--stall-rounds</code> 4 scrolls with nothing new. Rows are normalised into one schema whatever the source, and <code>price_source</code> records whether each one came from <code>embedded_json</code>, <code>json_ld</code> or <code>json_ld_min_variant</code>. The three engines share one page loop in <code>page_flow.py</code>, so the flags are the same whichever one you run.</p>
<h2>CAPTCHAs and blocks on SHEIN</h2>
<p>SHEIN's risk gateway has two outcomes, and the scraper treats them differently.</p>
<p><code>/risk/challenge</code> is a bot check you can pass. The scraper first clicks the "I am human" checkbox, which costs nothing. If SHEIN escalates, it takes a screenshot of the puzzle and sends it to 2Captcha: a 3x3 image grid goes as a GridTask, a "click the icons in order" puzzle as a CoordinatesTask. It retries with a fresh puzzle up to <code>--risk-challenge-rounds</code> times (default 5).</p>
<p><code>/risk/action/limit</code> is a rate limit. There's no puzzle, so nothing to pay for. The run exits with code 3, or with <code>--rate-limit-cooldown 300</code> it waits five minutes and retries once.</p>
<p>Three flags control spending:</p>
<pre><code class="language-bash">python3 playwright_scraper.py --query "crochet top" --max-results 20 \
  --solve-captcha when-blocked --max-solves 3 --out crochet_tops.json
</code></pre>
<p><code>--solve-captcha</code> takes <code>off</code>, <code>when-blocked</code> (the default) or <code>always</code>. <code>--max-solves</code> caps paid solves per run (default 8, and <code>0</code> means never pay); the number used goes into the metadata as solves spent. For a research run like this one I'd set it lower than the default: if a search needs more than a few solves, the browser profile is probably flagged, and more solves won't fix that.</p>
<p>The README is upfront that solving isn't guaranteed. In its test on 2026-09-30 with fresh US Scraping Browser API profiles, 3 of 5 got through, each on the third round, since SHEIN usually refuses the first one or two correct answers. The other two profiles were refused every time because SHEIN had flagged the profile itself, and those runs exit 3.</p>
<p>Which brings up the browser side. The same <code>TWOCAPTCHA_KEY</code> also works with the <a href="https://2captcha.com/?utm_source=hashnode&amp;utm_medium=article&amp;utm_campaign=shein-scraper">2Captcha</a> Scraping Browser API, a remote browser you connect to through <code>SHEIN_CDP_ENDPOINT</code>. CAPTCHA solving and the remote browser are separate services, billed separately. Profiles wear out: an HTTP 401 means it's time for a fresh endpoint, and after about ten runs in a row a profile may be rate-limited for a few minutes. Selenium can't authenticate a remote endpoint, which is one more reason to stay on Playwright.</p>
<h2>What a SHEIN product record looks like</h2>
<p>Here are selected fields from one row of <code>sample_output.json</code> in the repository:</p>
<pre><code class="language-json">{
  "sku": "499485260",
  "source": "shein.com",
  "category": "Women Mini Dresses",
  "brand": "jotten",
  "price": 8.55,
  "currency": "USD",
  "price_source": "embedded_json",
  "scraped_at": "2026-09-30T12:56:49Z",
  "original_price": 13.79,
  "discount_pct": 38.0,
  "rating": 4.8,
  "review_count": 143,
  "store_code": "8891882265",
  "in_stock": true,
  "is_clearance": false,
  "quickship": false
}
</code></pre>
<p>Each row also has <code>title</code>, <code>product_url</code> and <code>image_url</code>. <code>original_price</code> and <code>discount_pct</code> are null when there's no discount, and <code>rating</code> is null when there are no reviews. Output is JSON by default or CSV with <code>--format csv</code>.</p>
<h2>Size up the niche with pandas</h2>
<p>The script below turns the search into one row per seller (<code>store_code</code>): how many products they list, their median price, what share is discounted, and how many reviews they have in total. Install pandas first, since it isn't in the scraper's requirements:</p>
<pre><code class="language-bash">pip install pandas
</code></pre>
<p>Save this as <code>niche.py</code>:</p>
<pre><code class="language-python">import sys

import pandas as pd

path = sys.argv[1] if len(sys.argv) &gt; 1 else "crochet_tops.json"
df = pd.read_json(path, dtype={"sku": str, "store_code": str})
df = df[(df["currency"] == "USD") &amp; (df["in_stock"] == True)]

by_store = (
    df.groupby("store_code")
    .agg(
        products=("sku", "count"),
        median_price=("price", "median"),
        discounted_pct=("discount_pct", lambda s: round(s.notna().mean() * 100)),
        reviews=("review_count", "sum"),
        avg_rating=("rating", "mean"),
    )
    .sort_values("reviews", ascending=False)
    .round(2)
)

print(f"{len(df)} in-stock products, median price ${df['price'].median():.2f}")
print(by_store.head(10).to_string())
by_store.to_csv("niche_by_store.csv")
</code></pre>
<p>Run it with <code>python3 niche.py crochet_tops.json</code>. A few details are intentional. <code>discount_pct</code> is null for undiscounted items, so <code>notna()</code> counts discounted ones directly. <code>mean()</code> skips null ratings, so a product with no reviews doesn't drag a seller toward zero stars. And <code>sku</code> and <code>store_code</code> are read as strings, so long IDs don't turn into floats.</p>
<p>If you try it on the repository's <code>sample_output.json</code> first, keep in mind that file holds three mini dresses, not crochet tops. They come from two stores, one of which lists two of them.</p>
<h2>Limitations</h2>
<ul>
<li>Only <a href="http://us.shein.com">us.shein.com</a> is tested. Other country sites are untested, so changing the domain isn't a supported way to switch region or currency.</li>
<li>Listings beyond the first ~20 products are unverified, so a niche summary covers what was collected, not the whole category. Check <code>total_results</code> in the metadata against your row count.</li>
<li>Rows are per product, not per variant. You can't answer "is size M in stock?" from this output.</li>
<li><code>--sort</code> is recorded but not yet sent to SHEIN, so you can't ask for cheapest-first results.</li>
<li>Reviews come as <code>rating</code> and <code>review_count</code> only, with no review text.</li>
<li>The bot check isn't always solvable, so plan for runs that exit 3.</li>
</ul>
<h2>Scraping SHEIN legally and politely</h2>
<p>Collect public product data only, read SHEIN's terms of service and robots.txt before you run anything, and keep the request rate moderate: one small search at a time, and stop when access is refused. This workflow doesn't log in or touch customer accounts. If you ever extend it to anything that identifies people, such as reviewer names, GDPR and similar laws apply.</p>
<h2>FAQ</h2>
<h3>Does SHEIN have a public API for product data?</h3>
<p>This scraper doesn't use one. It reads the product data SHEIN already embeds in its pages, <code>window.gbRawData</code> on listings and JSON-LD on product pages, so you don't need API access to collect it.</p>
<h3>How do I scrape SHEIN without getting blocked?</h3>
<p>Keep runs small and spaced out, and let the scraper handle the risk gateway: it clicks the free checkbox first and sends harder puzzles to 2Captcha only when blocked. If a run exits 3 with <code>stop_reason: rate_limited</code>, wait it out with <code>--rate-limit-cooldown 300</code> instead of retrying straight away.</p>
<h3>How much does scraping SHEIN cost?</h3>
<p>The scraper is free and MIT-licensed, and a local run without a key costs nothing. Paid parts are CAPTCHA solves, capped per run by <code>--max-solves</code>, plus any remote browser or proxy you add. Check 2Captcha's current prices for those.</p>
<h3>Can I build a SHEIN price tracker in Python?</h3>
<p>Yes. Save each run to a dated file and compare two complete runs with <code>python3 diff_runs.py old.json new.json</code>, which reports added, removed and price-changed products by <code>sku</code>. With <code>--fail-on-change</code> it exits 1 on a real price change, so a cron job can alert you.</p>
<h3>Can I scrape SHEIN reviews?</h3>
<p>Only as numbers. Each row has <code>rating</code> and <code>review_count</code>, but not review text or reviewer details, so this scraper won't collect individual reviews.</p>
<h3>How do I export SHEIN data to CSV?</h3>
<p>Add <code>--format csv --out yourfile.csv</code> to the run, or convert the JSON afterwards with pandas as in <code>niche.py</code>. The CSV and JSON contain the same fields.</p>
<h2>Where to go from here</h2>
<p>The same steps work for any niche: change the <code>--query</code>, rerun, and compare seller tables over a few weeks. The code and the full flag table are in the <a href="https://github.com/2scraper/shein-scraper">shein-scraper repository on GitHub</a>, and there are details and more scrapers on the <a href="https://2scraper.com/scrapers/shein-scraper/">SHEIN Scraper page at 2scraper.com</a>. 2Captcha's own guide, How to scrape SHEIN, is the full reference of all options. If SHEIN starts challenging your runs, add a 2Captcha key to <code>.env</code> and keep <code>--max-solves</code> low.</p>
]]></content:encoded></item></channel></rss>