Repository navigation
Scraper API: send waitFor as an object, read the target status from http_code - #6
Merged
Merged
Conversation
…ttp_code Two defects in scraper_api_client.py, both measured 2026-09-23 against https://scraper.2captcha.com/tasks/sync: - waitFor was sent as a JSON-encoded string. The API answers that with HTTP 422 "params.waitFor must be an object" and still bills $0.0005; the object form answers HTTP 200. Every --wait-* run was a paid exit 5. - The target status was read from `status`, which is the API's own verdict string ("success"); the target's code is `http_code`. A target 403/503 therefore never reached detect_page_state. `status` is now a fallback only when it is an int. Adds test_scraper_api_waitfor_is_an_object to smoke_test.py (real parse_args/fetch_html, requests.post captured, no network). Control: with the old client restored the suite goes red on exactly those two checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two defects in the Scraper API client
Measured 2026-09-23 against
https://scraper.2captcha.com/tasks/sync.waitForwas sent as a JSON-encoded string._build_wait_forreturnedjson.dumps({...}), following a docstring that said the API wanted a double-encoded string. The live API refuses that with HTTP 422ScrapeParser: params.waitFor must be an object— and still bills the call ($0.0005). The same request with an object answers HTTP 200. So every--wait-text/--wait-element/--wait-staterun was a paid exit 5._build_wait_fornow returns a dict (Optional[dict]), logged throughjson.dumps, and the docstring says what was measured.status. The response is{"status": "success", "http_code": <int>, "headers": …, "body": …}:statusis the API's own verdict string,http_codeis the target site's HTTP code. The client passed"success"intodetect_page_state, so a target 403/503 was never seen (a live rakuten run loggedUpstream page status success). It now readshttp_code, falling back tostatusonly if that is an int.Regression check
test_scraper_api_waitfor_is_an_objectinsmoke_test.py: drives the realparse_args()+fetch_html()with--wait-text,requests.postmonkeypatched to capture the payload and return{"status":"success","http_code":403,"body":"<html></html>"}. AssertswaitForis a dict and the status handed onward is the int 403.Control: with
scraper_api_client.pyrestored fromorigin/main(edit asserted to change the file) the suite went red on exactly those two checks and nothing else; with the fix it is green.Live result
One call with the fixed client, key from the environment:
→ API HTTP 200 (no 422),
Upstream page status 200 (target HTTP code, from http_code), 1,875,638 bytes, real page title ("1553 Used Cars in Delhi …").But 0 products parsed, exit 4. The HTML carries no
/buy-used-cars/links at all — the car grid had not been painted into what came back (the wait text "Maruti" occurs once in the document, outside any grid). So the waitFor 422 is fixed; whether this client can read Spinny's grid at all is a separate open question, not addressed here. Worth a follow-up with--wait-elementon a grid selector.Not changed
[Unreleased].detect_page_stateare untouched — they already take an int status; they were just never given one.🤖 Generated with Claude Code