Skip to content

Scraper API: send waitFor as an object, read the target status from http_code - #15

Merged
jehrr merged 1 commit into
mainfrom
fix/scraper-api-waitfor-object
Sep 23, 2026
Merged

jehrr merged 1 commit into
mainfrom
fix/scraper-api-waitfor-object

Conversation

@jehrr

@jehrr jehrr commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

Two defects in scraper_api_client.py

Measured 2026-09-23 against https://scraper.2captcha.com/tasks/sync:

  1. waitFor sent as a JSON-encoded string (what _build_wait_for returned) is answered HTTP 422 ScrapeParser: params.waitFor must be an object — and the call is still billed ($0.0005). The same request with an object answers 200. So every run with --wait-text / --wait-element / --wait-state failed with exit 5 and cost money. _build_wait_for now returns a dict (logged through json.dumps), and the docstring that said the API wanted a double-encoded string now says what was measured.
  2. The target status was read from status, which is the API's own verdict string ("success"). The target site's HTTP code is http_code. The client handed "success" onward, so a target 403/503 never reached the page classifier. It now reads http_code (int), falling back to status only if that is itself an int.

Regression check

test_scraper_api_sends_waitfor_as_an_object_and_reads_http_code in smoke_test.py: drives the real function with requests.post stubbed (no network), returning {"status":"success","http_code":403,"body":"<html></html>"}, and asserts (a) the payload's waitFor is a dict and (b) the status handed onward is 403 (int).

Control: (registered with ok &= … in main(), this suite's shape) with origin/main's scraper_api_client.py swapped into this branch's tree (file hash confirmed changed), the suite went red with exactly 2 failures, both this check's messages (waitFor came back as the string '{"text": "mug"}', status as 'success'). Restored: smoke_test: OK.

Live result

One call, key from the environment: scraper_api_client.py --url 'https://www.etsy.com/search?q=handmade+mug' --wait-text mug, no --cdp-url → API answered HTTP 408 {"error":"timeout","status":"pending"} after 60 s (the default --timeout), exit 5. So the object-form waitFor was accepted (no 422), but that call produced no target status to log — the http_code half is verified offline only for this repo. Not retried: one paid call per repo.

Not changed

The three browser engines, product_parser.py, the page classifier and the default --timeout are untouched. No version bump — the CHANGELOG entry is under [Unreleased]. Reference fix: zimmo-scraper PR #1.

🤖 Generated with Claude Code

…ttp_code

Measured 2026-09-23 against the live /tasks/sync endpoint: waitFor sent
as a JSON-encoded string is answered HTTP 422 "params.waitFor must be an
object" and still billed ($0.0005); as an object it is answered 200.
The response's `status` is the API's own verdict ("success"); the
target's HTTP code is `http_code`, which is now what reaches the page
classifier (fallback to `status` only when it is an int).

Adds one offline regression check, controlled: with the old client the
suite goes red on exactly that check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jehrr

jehrr commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator Author

Second live call on this branch (2026-09-23, --timeout 120, --url 'https://www.etsy.com/search?q=handmade+mug' --wait-text mug): API accepted the object waitFor (no 422) and answered HTTP 408 {"error":"timeout","status":"pending"} after 120 s. So the payload fix is live-verified; the http_code half is verified offline only, because this site's page did not finish inside the API's sync window on either call. Not a regression: the unfixed client would have got a billed 422 before reaching the site.

@jehrr
jehrr merged commit 2b04b9d into main Sep 23, 2026
7 checks passed
@jehrr
jehrr deleted the fix/scraper-api-waitfor-object branch September 23, 2026 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant