Spaces:
Sleeping
Sleeping
Always use residential proxies in India (super=true, geoCode=in)
Browse files36 unmodified lines3738394041424310 unmodified lines545556575859606136 unmodified lines## 🔑 Get your free API token👉 **[Sign up free on Scrape.do](https://dashboard.scrape.do/sign-up?utm_source=huggingface&utm_medium=zepto-scraper)** — 1,000 free credits per month, no credit card required. Every Zepto page costs 1 credit.## Two tabs10 unmodified linesuser agent it gets HTTP 202, an empty body and `x-amzn-waf-action: challenge`,which `raise_for_status()` happily treats as success. Through[Scrape.do](https://scrape.do/?utm_source=huggingface&utm_medium=zepto-scraper)a plain request (no rendering, no premium proxies) returns the full page for onecredit, and the product data is already in the HTML as a Next.js stream.Good to know:36 unmodified lines3738394041424310 unmodified lines54555657585960616236 unmodified lines## 🔑 Get your free API token👉 **[Sign up free on Scrape.do](https://dashboard.scrape.do/sign-up?utm_source=huggingface&utm_medium=zepto-scraper)** — 1,000 free credits per month, no credit card required. Every Zepto page costs 10 credits.## Two tabs10 unmodified linesuser agent it gets HTTP 202, an empty body and `x-amzn-waf-action: challenge`,which `raise_for_status()` happily treats as success. Through[Scrape.do](https://scrape.do/?utm_source=huggingface&utm_medium=zepto-scraper)each page goes through residential proxies in India (`super=true&geoCode=in`,10 credits, about 3 seconds) and comes back in full, with the product dataalready in the HTML as a Next.js stream. No rendering needed.Good to know:
30 unmodified lines31323334353637252 unmodified lines29029129229329429529697 unmodified lines3943953963973983994007 unmodified lines40840941041141241341441541631 unmodified lines4484494504514524534549 unmodified lines46446546646746846947030 unmodified linesNO_TOKEN_MD = ("### Paste your Scrape.do API token above\n\n"f"No token yet? [Create a free account]({SCRAPE_DO_SIGNUP_URL}) — ""1,000 free credits a month, no credit card. Every Zepto page costs 1 credit.")# --------------------------------------------------------------------- helpers252 unmodified linesproduct = dict(data.get("product") or {})product["images"] = " | ".join(product.get("images") or [])note = (f"{data.get('credits_used')} credit used. Price and stock are left out here on purpose: the product ""page caps the stock count. Use the **Category listings** tab for those.")return note, render_product(data), data, _write_csv([product], "zepto-product")97 unmodified linesincluded. Open any product for its seller, shelf life and FSSAI licence.</p><p>Zepto answers scripts with an empty AWS WAF challenge. This Space fetches the pages through<a href="https://scrape.do/?utm_source=huggingface&utm_medium=zepto-scraper" target="_blank" rel="noopener noreferrer">Scrape.do</a>with one plain request per page (1 credit) and reads the product data Zepto streams into the HTML.</p><a class="zp-cta" href="{SCRAPE_DO_SIGNUP_URL}" target="_blank" rel="noopener noreferrer">Get a free API token →</a></div><div class="zp-hero-card" aria-hidden="true">7 unmodified linesCREDIT_NOTE = """<div class="zp-note">Every Zepto page costs 1 credit: one subcategory (up to 32 products) or one product page. Walking a whole categoryof 9 subcategories costs 9 credits. If Zepto blocks the plain request, the Space retries that page once throughScrape.do's residential proxies in India (10 credits). The free 1,000 credits a month cover up to 1,000 pages.</div>"""31 unmodified lineslabel="Scrape.do API token",placeholder="Paste your token here",type="password",info="Free tier: 1,000 credits a month. 1 credit per Zepto page.",)gr.HTML(CREDIT_NOTE)9 unmodified lineswalk = gr.Checkbox(label="Also read the sibling subcategories", value=False)max_subs = gr.Slider(minimum=1, maximum=MAX_SUBCATEGORIES, step=1, value=9,label="Max subcategories (1 credit each)",)hide_oos = gr.Checkbox(label="Hide out-of-stock cards", value=False)cat_btn = gr.Button("Scrape category", variant="primary")30 unmodified lines31323334353637252 unmodified lines29029129229329429529697 unmodified lines3943953963973983994007 unmodified lines40840941041141241341441541631 unmodified lines4484494504514524534549 unmodified lines46446546646746846947030 unmodified linesNO_TOKEN_MD = ("### Paste your Scrape.do API token above\n\n"f"No token yet? [Create a free account]({SCRAPE_DO_SIGNUP_URL}) — ""1,000 free credits a month, no credit card. Every Zepto page costs 10 credits.")# --------------------------------------------------------------------- helpers252 unmodified linesproduct = dict(data.get("product") or {})product["images"] = " | ".join(product.get("images") or [])note = (f"{data.get('credits_used')} credits used. Price and stock are left out here on purpose: the product ""page caps the stock count. Use the **Category listings** tab for those.")return note, render_product(data), data, _write_csv([product], "zepto-product")97 unmodified linesincluded. Open any product for its seller, shelf life and FSSAI licence.</p><p>Zepto answers scripts with an empty AWS WAF challenge. This Space fetches the pages through<a href="https://scrape.do/?utm_source=huggingface&utm_medium=zepto-scraper" target="_blank" rel="noopener noreferrer">Scrape.do</a>through residential proxies in India (10 credits per page) and reads the product data Zepto streams into the HTML.</p><a class="zp-cta" href="{SCRAPE_DO_SIGNUP_URL}" target="_blank" rel="noopener noreferrer">Get a free API token →</a></div><div class="zp-hero-card" aria-hidden="true">7 unmodified linesCREDIT_NOTE = """<div class="zp-note">Every Zepto page costs 10 credits: one subcategory (up to 32 products) or one product page, fetched throughScrape.do's residential proxies in India. Walking a whole category of 9 subcategories costs 90 credits. The free1,000 credits a month cover about 100 pages.</div>"""31 unmodified lineslabel="Scrape.do API token",placeholder="Paste your token here",type="password",info="Free tier: 1,000 credits a month. 10 credits per Zepto page.",)gr.HTML(CREDIT_NOTE)9 unmodified lineswalk = gr.Checkbox(label="Also read the sibling subcategories", value=False)max_subs = gr.Slider(minimum=1, maximum=MAX_SUBCATEGORIES, step=1, value=9,label="Max subcategories (10 credits each)",)hide_oos = gr.Checkbox(label="Hide out-of-stock cards", value=False)cat_btn = gr.Button("Scrape category", variant="primary")
14 unmodified lines151617181920212223204 unmodified lines22822923023123223323423523623723823924030 unmodified lines27127227327427527627727827928028128228328428528628728828929011 unmodified lines30230330430530630730830931031114 unmodified lines)API_URL = "https://api.scrape.do/"ZEPTO = "https://www.zepto.com"# A plain Scrape.do request (no render, no super, no geoCode) usually returns the full Zepto page;# when it doesn't, _fetch retries once with super=true&geoCode=in.CREDITS_PER_PAGE = 1DEFAULT_SUBCATEGORY_URL = ("https://www.zepto.com/cn/munchies/chips-crisps/cid/d2c2a144-43cd-43e5-b308-92628fa68596""/scid/df4f5100-c02f-4906-83b8-ddb744081a7a"204 unmodified linesorigin, images and description.Pass a Zepto subcategory URL (/cn/.../cid/.../scid/...) or product URL (/pn/.../pvid/...).Powered by Scrape.do, which gets past the AWS WAF challenge Zepto shows to scripts.One credit per page."""output_type = "string"def __init__(self, api_token: Optional[str] = None) -> None:self._api_token = api_tokenself._plain_blocked = Falseself.inputs = {"mode": {"type": "string",30 unmodified lines"hint": f"Get a free token at {SCRAPE_DO_SIGNUP_URL}",}# Attempt 1 is a plain request (1 credit). If Zepto's WAF still blocks it, attempt 2# goes through Scrape.do's residential pool in India (super=true, 10 credits).# The plain attempt gets a short Scrape.do timeout so a failed rotation costs ~15 s, not ~60 s.ATTEMPTS = (({"timeout": "15000"}, 1), ({"super": "true", "geoCode": "in"}, 10))def _fetch(self, token: str, url: str) -> Dict[str, Any]:"""GET a Zepto page through Scrape.do. Anything other than HTTP 200 is a failure:Zepto's AWS WAF answers scripts with an empty 202, which requests treats as success."""last: Dict[str, Any] = {"_error": "Request failed."}attempts = self.ATTEMPTS[1:] if self._plain_blocked else self.ATTEMPTSfor attempt, (extra, credits) in enumerate(attempts, start=1):params = {"token": token, "url": url, **extra}started = time.time()print(f"[fetch] attempt {attempt} {extra or 'plain'}: {url}", flush=True)try:response = requests.get(API_URL, params=params, timeout=(10, 90))except requests.exceptions.Timeout:11 unmodified linesif response.status_code == 401:return {"_error": "Scrape.do rejected the token (HTTP 401).", "_auth": True}if response.status_code == 200 and body:return {"html": body, "_credits": credits}if "super" not in extra:# Plain requests are being blocked right now; skip them for the rest of this run.self._plain_blocked = Trueif response.status_code != 200:print(f"[fetch] body: {body[:300].replace(token, '***')}", flush=True)last = {"_error": f"Zepto didn't return the page (HTTP {response.status_code}).",14 unmodified lines1516171819202122204 unmodified lines22722822923023123223323423523623723830 unmodified lines26927027127227327427527627727827928028128228328428528611 unmodified lines29829930030130230330414 unmodified lines)API_URL = "https://api.scrape.do/"ZEPTO = "https://www.zepto.com"# Every page goes through Scrape.do residential proxies in India (super=true&geoCode=in).CREDITS_PER_PAGE = 10DEFAULT_SUBCATEGORY_URL = ("https://www.zepto.com/cn/munchies/chips-crisps/cid/d2c2a144-43cd-43e5-b308-92628fa68596""/scid/df4f5100-c02f-4906-83b8-ddb744081a7a"204 unmodified linesorigin, images and description.Pass a Zepto subcategory URL (/cn/.../cid/.../scid/...) or product URL (/pn/.../pvid/...).Powered by Scrape.do, which gets past the AWS WAF challenge Zepto shows to scripts.10 Scrape.do credits per page."""output_type = "string"def __init__(self, api_token: Optional[str] = None) -> None:self._api_token = api_tokenself.inputs = {"mode": {"type": "string",30 unmodified lines"hint": f"Get a free token at {SCRAPE_DO_SIGNUP_URL}",}# Zepto's WAF blocks Scrape.do's default rotation (502 ROTATION_FAILED after ~60 s), so every# page goes straight through the residential pool in India: about 3 s, 10 credits.PARAMS = {"super": "true", "geoCode": "in"}def _fetch(self, token: str, url: str) -> Dict[str, Any]:"""GET a Zepto page through Scrape.do. Anything other than HTTP 200 is a failure:Zepto's AWS WAF answers scripts with an empty 202, which requests treats as success."""last: Dict[str, Any] = {"_error": "Request failed."}for attempt in (1, 2):params = {"token": token, "url": url, **self.PARAMS}started = time.time()print(f"[fetch] attempt {attempt}: {url}", flush=True)try:response = requests.get(API_URL, params=params, timeout=(10, 90))except requests.exceptions.Timeout:11 unmodified linesif response.status_code == 401:return {"_error": "Scrape.do rejected the token (HTTP 401).", "_auth": True}if response.status_code == 200 and body:return {"html": body, "_credits": CREDITS_PER_PAGE}if response.status_code != 200:print(f"[fetch] body: {body[:300].replace(token, '***')}", flush=True)last = {"_error": f"Zepto didn't return the page (HTTP {response.status_code}).",
README.md+4-3
app.py+8-8
tool.py+10-17