Skip to content

Google: link_token on search results, search.resolve() and resolve_all() (0.82.0) (SCR-667) - #107

Merged
0xGhostCasper merged 1 commit into
mainfrom
kasparasizi1/scr-667-google-resolve
Nov 23, 2026
Merged

0xGhostCasper merged 1 commit into
mainfrom
kasparasizi1/scr-667-google-resolve

Conversation

@0xGhostCasper

Copy link
Copy Markdown
Member

What changed

  • Search results. In google.search.search() and google.search.light() responses, an organic_results item whose link is still a Google redirect (https://www.google.com/goto?url=...) now has link_token (string) and retry_after_seconds (int, 0 = can be resolved right away). Both are None when link is already the real URL. These responses are plain dicts, so the fields pass through with no code change. The docstrings and docs now describe them.
  • google.search.resolve(results) (new). One POST /v1/google/resolve with {"results": [...]}. Returns the response dict unchanged: {"results": [...], "retry_after_seconds": int | None}. No client-side validation. Costs no credits.
  • google.search.resolve_all(results, *, max_wait=240.0) (new). A loop around resolve:
    • Sends the rows that have a link_token and no error, at most 25 per request.
    • Puts the answers back in the input order, sleeps the smallest retry_after_seconds returned (at least 1 second, never past max_wait), then sends the rows that are still not ready, with their latest token.
    • Stops when no row is waiting or when max_wait seconds have passed. Rows that are still not ready are returned with their latest link_token and retry_after_seconds. No exception is raised for them.
    • Rows without a link_token are returned as they are and never sent. The input list and its dicts are not changed. The result is a new list.
  • Docs. docs/google.md: the two new organic fields, resolve and resolve_all in the Methods table, a "Resolving result links" section with a runnable example and the meaning of each row state, and a 0-credit row in the cost table. One line in README.md. New CHANGELOG.md entry.
  • Version 0.82.0 in pyproject.toml, SDK_VERSION, __version__ and uv.lock.

No existing signature changes. Nothing inside a generated block was edited.

resolve(self, results: list[dict[str, Any]]) -> dict[str, Any]
resolve_all(self, results: list[dict[str, Any]], *, max_wait: float = 240.0) -> list[dict[str, Any]]

How it was tested

  • uv run pytest --ignore=tests/e2e: 1022 passed, 0 failed. tests/test_google.py has 65 tests, 13 of them new:
    • resolve posts {"results": [...]} to /v1/google/resolve and returns the dict.
    • resolve_all: resolved on the first call; a row that is not ready is sent again with the new token after sleeping the returned wait; a wait of 0 or no wait becomes 1 second; a failed row is returned and not sent again; a row that already has error is never sent; 60 rows go out as 25, 25 and 10; with several requests the smallest wait is used; at the deadline the last sleep is cut, the rows come back with their latest tokens and nothing is raised; max_wait=0 sends each row once; rows without link_token are never sent and keep their position; nothing to resolve makes no request; the input is not mutated.
  • uv run pytest with no API key set: 1022 passed, 77 skipped. The 77 are tests/e2e, which call the live API.
  • uv run ruff check src/ tests/: all checks passed.
  • uv run ruff format --check src/ tests/: 308 files already formatted.
  • uv run mypy src/: no issues found in 257 source files.
  • Both examples in the new docs section were run against a locally mocked API (respx), through the real HTTP layer.
  • Not run against the live API.

Release

Do not release before POST /v1/google/resolve is live.

🤖 Generated with Claude Code

…l() (0.82.0) (SCR-667)

- google.search.resolve(results): one POST /v1/google/resolve with
  {"results": [...]}. Returns the response dict unchanged. Costs no credits.
- google.search.resolve_all(results, *, max_wait=240.0): sends the rows that
  have a link_token, at most 25 per request, sleeps the smallest
  retry_after_seconds returned (at least 1 second, never past max_wait) and
  repeats until no row is waiting or max_wait has passed. Returns a new list
  in the input order and does not change the input. Rows still not ready at
  max_wait are returned with their latest link_token and retry_after_seconds;
  no exception is raised. Rows with an error and rows without a link_token
  are not sent.
- search() and light() docstrings, docs/google.md, README and CHANGELOG
  describe link_token and retry_after_seconds on organic_results.
- Version 0.82.0 in pyproject, SDK_VERSION, __version__ and uv.lock.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.87500% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/scrapebadger/google/search.py 96.66% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@0xGhostCasper
0xGhostCasper merged commit 839420b into main Nov 23, 2026
7 checks passed
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.

2 participants