diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e74896..8b01e2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.84.0 + +- Search and Light accept `defer_links=True` to skip inline organic URL lookups. Use `resolve()` or `resolve_all()` when destinations are needed. + ## [0.83.1] - 2026-11-26 ### Changed diff --git a/pyproject.toml b/pyproject.toml index 9b2d312..fbfa0af 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "scrapebadger" -version = "0.83.1" +version = "0.84.0" description = "Official Python SDK for ScrapeBadger - Async web scraping APIs for Twitter and more" readme = "README.md" license = { text = "MIT" } diff --git a/src/scrapebadger/__init__.py b/src/scrapebadger/__init__.py index 6e9069f..1c31bdc 100644 --- a/src/scrapebadger/__init__.py +++ b/src/scrapebadger/__init__.py @@ -1356,7 +1356,7 @@ async def main(): ZestimateHistoryPoint as ZillowZestimateHistoryPoint, ) -__version__ = "0.83.1" +__version__ = "0.84.0" __all__ = [ # TikTok core models diff --git a/src/scrapebadger/_internal/client.py b/src/scrapebadger/_internal/client.py index dadf57a..f51df4d 100644 --- a/src/scrapebadger/_internal/client.py +++ b/src/scrapebadger/_internal/client.py @@ -56,7 +56,7 @@ T = TypeVar("T") # User agent for SDK requests -SDK_VERSION = "0.83.1" +SDK_VERSION = "0.84.0" USER_AGENT = f"scrapebadger-python/{SDK_VERSION}" diff --git a/src/scrapebadger/google/search.py b/src/scrapebadger/google/search.py index 11eac96..a45c3da 100644 --- a/src/scrapebadger/google/search.py +++ b/src/scrapebadger/google/search.py @@ -88,6 +88,7 @@ async def search( sourceid: str | None = None, ie: str | None = None, user_agent: str | None = None, + defer_links: bool = False, output: Literal["html"], ) -> str: ... @@ -142,6 +143,7 @@ async def search( sourceid: str | None = None, ie: str | None = None, user_agent: str | None = None, + defer_links: bool = False, output: Literal["json"] = "json", ) -> dict[str, Any]: ... @@ -196,6 +198,7 @@ async def search( sourceid: str | None = None, ie: str | None = None, user_agent: str | None = None, + defer_links: bool = False, output: Literal["json", "html"], ) -> dict[str, Any] | str: ... @@ -249,6 +252,7 @@ async def search( sourceid: str | None = None, ie: str | None = None, user_agent: str | None = None, + defer_links: bool = False, output: Literal["json", "html"] = "json", ) -> dict[str, Any] | str: """Search Google and get a structured SERP response. @@ -278,6 +282,7 @@ async def search( sourceid: Google source identifier. Defaults to chrome; an empty string omits it. ie: Google input encoding hint. Defaults to UTF-8; an empty string omits it. user_agent: Custom User-Agent override. + defer_links: Skip inline URL lookups and return link tokens for resolve(). output: json returns structured results; html returns the raw page. q: Search query (supports Google operators like `site:`, `intitle:`). gl: Country code (default "us"). @@ -427,6 +432,8 @@ async def search( params["expand_related_questions"] = expand_related_questions if mode != "full": params["mode"] = mode + if defer_links: + params["defer_links"] = True if output == "html": body, _, _ = await self._client.get_raw("/v1/google/search", params=params) return body.decode("utf-8") @@ -480,6 +487,7 @@ async def light( sourceid: str | None = None, ie: str | None = None, user_agent: str | None = None, + defer_links: bool = False, output: Literal["html"], ) -> str: ... @@ -531,6 +539,7 @@ async def light( sourceid: str | None = None, ie: str | None = None, user_agent: str | None = None, + defer_links: bool = False, output: Literal["json"] = "json", ) -> dict[str, Any]: ... @@ -582,6 +591,7 @@ async def light( sourceid: str | None = None, ie: str | None = None, user_agent: str | None = None, + defer_links: bool = False, output: Literal["json", "html"], ) -> dict[str, Any] | str: ... @@ -632,6 +642,7 @@ async def light( sourceid: str | None = None, ie: str | None = None, user_agent: str | None = None, + defer_links: bool = False, output: Literal["json", "html"] = "json", ) -> dict[str, Any] | str: """Google Light Search — organic results + related searches only. @@ -670,6 +681,7 @@ async def light( sourceid: Google source identifier. Defaults to chrome; an empty string omits it. ie: Google input encoding hint. Defaults to UTF-8; an empty string omits it. user_agent: Custom User-Agent override. + defer_links: Skip inline URL lookups and return link tokens for resolve(). output: json returns structured results; html returns the raw page. q: Search query (supports Google operators like `site:`). gl: Country code (default "us"). @@ -749,6 +761,8 @@ async def light( "ibp": ibp, "uds": uds, } + if defer_links: + params["defer_links"] = True if output == "html": body, _, _ = await self._client.get_raw("/v1/google/light/search", params=params) return body.decode("utf-8") diff --git a/tests/test_google_deferred_links.py b/tests/test_google_deferred_links.py new file mode 100644 index 0000000..17ee411 --- /dev/null +++ b/tests/test_google_deferred_links.py @@ -0,0 +1,19 @@ +from unittest.mock import AsyncMock + +import pytest + +from scrapebadger.google.search import SearchClient + + +@pytest.mark.asyncio +@pytest.mark.parametrize( + "method,path", [("search", "/v1/google/search"), ("light", "/v1/google/light/search")] +) +async def test_deferred_links_is_opt_in_and_forwarded(method, path): + base = AsyncMock() + client = SearchClient(base) + await getattr(client, method)("cats") + assert "defer_links" not in base.get.call_args.kwargs["params"] + await getattr(client, method)("cats", defer_links=True) + assert base.get.call_args.args[0] == path + assert base.get.call_args.kwargs["params"]["defer_links"] is True diff --git a/uv.lock b/uv.lock index c53bd93..485e93d 100644 --- a/uv.lock +++ b/uv.lock @@ -930,7 +930,7 @@ wheels = [ [[package]] name = "scrapebadger" -version = "0.83.1" +version = "0.84.0" source = { editable = "." } dependencies = [ { name = "httpx" },