Skip to content

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

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, both measured 2026-09-23 against https://scraper.2captcha.com/tasks/sync.

1. waitFor was sent as a JSON-encoded string. The live API now answers that with HTTP 422 params.waitFor must be an object — and still bills the task ($0.0005). So every run with --wait-text / --wait-element / --wait-state ended in exit 5. Sent as an object it answers 200. _build_wait_for now returns a dict (Optional[dict]), logged with json.dumps; its docstring says what was measured instead of claiming a string is required.

2. The target status was read from status. The response is {"status": "success", "http_code": <int>, …}: status is the API's verdict string, http_code the target's HTTP code. fetch_html returns the status to _run_once, which hands it to detect_page_state(html, status=…), so the classifier received "success" and a target 403/404/503 could not be read by its status. New _target_status() reads http_code (int), falling back to status only if that is an int.

Regression check — check_scraper_api_waitfor_object_and_http_code in smoke_test.py, picked up by the suite's check_ auto-discovery (defined above the CHECKS = [...] line, so it is collected): drives the real fetch_html with requests.post monkeypatched (no network), asserts the payload's waitFor is a dict for --wait-text 円, and that the status returned onward is the int 403 from a fake {"status":"success","http_code":403} response.

Control: with scraper_api_client.py restored to origin/main in a scratch copy (edit asserted to change the file), the suite went RED with both of this check's messages and no other failure; with the fix it is green (434 checks passed).

Live: one call through the fixed client, --wait-text 円, https://maison.kose.co.jp/site/cosmedecorte/c/c15/ (the canary URL): API HTTP 200, upstream status 200 (int, handed onward), 90,835 bytes, $0.0005; detect_page_state → content, 24 rows parsed.

Not changed, noticed in passing: python3 smoke_test.py -v (verbose) raises TypeError in 10 checks on origin/main too — the verbose branch of check() concatenates a non-string detail. The default, non-verbose run (what CI runs) is unaffected. Left for a separate fix. No version bump; entry under [Unreleased].

🤖 Generated with Claude Code

…ttp_code

Measured 2026-09-23 against scraper.2captcha.com/tasks/sync: waitFor sent
as a JSON-encoded string is refused with HTTP 422 ("params.waitFor must be
an object") and still billed; as an object it answers 200. The response's
status field is the API's verdict ("success"); the target's HTTP code is
http_code. Adds a no-network regression check, controlled red against the
unfixed client.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jehrr
jehrr merged commit ade4649 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