From b9c57072cf7f45aa6fb7ce49097b5e2f30eb7ef9 Mon Sep 17 00:00:00 2001 From: Marco Vinciguerra Date: Tue, 27 Jan 2026 15:02:23 +0100 Subject: [PATCH] feat: add location_geo_code parameter to SearchScraper - Add location_geo_code field to SearchScraperRequest model - Add location_geo_code parameter to sync and async searchscraper methods - Add logging for location_geo_code when provided - Aligns with API changes in sgai-api PR #384 --- scrapegraph-py/scrapegraph_py/async_client.py | 5 +++++ scrapegraph-py/scrapegraph_py/client.py | 7 ++++++- scrapegraph-py/scrapegraph_py/models/searchscraper.py | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/scrapegraph-py/scrapegraph_py/async_client.py b/scrapegraph-py/scrapegraph_py/async_client.py index 22331b0..350087d 100644 --- a/scrapegraph-py/scrapegraph_py/async_client.py +++ b/scrapegraph-py/scrapegraph_py/async_client.py @@ -782,6 +782,7 @@ async def searchscraper( output_schema: Optional[BaseModel] = None, extraction_mode: bool = True, stealth: bool = False, + location_geo_code: Optional[str] = None, return_toon: bool = False, ): """Send a searchscraper request @@ -797,6 +798,7 @@ async def searchscraper( extraction_mode: Whether to use AI extraction (True) or markdown conversion (False). AI extraction costs 10 credits per page, markdown conversion costs 2 credits per page. stealth: Enable stealth mode to avoid bot detection + location_geo_code: Optional geo code of the location to search in (e.g., "us") return_toon: If True, return response in TOON format (reduces token usage by 30-60%) """ logger.info("🔍 Starting searchscraper request") @@ -807,6 +809,8 @@ async def searchscraper( logger.debug("🔧 Using custom headers") if stealth: logger.debug("🥷 Stealth mode enabled") + if location_geo_code: + logger.debug(f"🌍 Location geo code: {location_geo_code}") if return_toon: logger.debug("🎨 TOON format output enabled") @@ -817,6 +821,7 @@ async def searchscraper( output_schema=output_schema, extraction_mode=extraction_mode, stealth=stealth, + location_geo_code=location_geo_code, ) logger.debug("✅ Request validation passed") diff --git a/scrapegraph-py/scrapegraph_py/client.py b/scrapegraph-py/scrapegraph_py/client.py index c47ba82..26ec272 100644 --- a/scrapegraph-py/scrapegraph_py/client.py +++ b/scrapegraph-py/scrapegraph_py/client.py @@ -792,6 +792,7 @@ def searchscraper( extraction_mode: bool = True, mock: bool=False, stealth: bool=False, + location_geo_code: Optional[str] = None, return_toon: bool = False, ): """Send a searchscraper request @@ -808,6 +809,7 @@ def searchscraper( AI extraction costs 10 credits per page, markdown conversion costs 2 credits per page. mock: Enable mock mode for testing stealth: Enable stealth mode to avoid bot detection + location_geo_code: Optional geo code of the location to search in (e.g., "us") return_toon: If True, return response in TOON format (reduces token usage by 30-60%) """ logger.info("🔍 Starting searchscraper request") @@ -818,6 +820,8 @@ def searchscraper( logger.debug("🔧 Using custom headers") if stealth: logger.debug("🥷 Stealth mode enabled") + if location_geo_code: + logger.debug(f"🌍 Location geo code: {location_geo_code}") if return_toon: logger.debug("🎨 TOON format output enabled") @@ -828,7 +832,8 @@ def searchscraper( output_schema=output_schema, extraction_mode=extraction_mode, mock=mock, - stealth=stealth + stealth=stealth, + location_geo_code=location_geo_code, ) logger.debug("✅ Request validation passed") diff --git a/scrapegraph-py/scrapegraph_py/models/searchscraper.py b/scrapegraph-py/scrapegraph_py/models/searchscraper.py index ce57ba5..f12f3ed 100644 --- a/scrapegraph-py/scrapegraph_py/models/searchscraper.py +++ b/scrapegraph-py/scrapegraph_py/models/searchscraper.py @@ -33,6 +33,7 @@ class SearchScraperRequest(BaseModel): extraction_mode: Use AI extraction (True) or markdown (False) mock: Whether to use mock mode for testing render_heavy_js: Whether to render heavy JavaScript + location_geo_code: Optional geo code for location-based search (e.g., "us") Example: >>> request = SearchScraperRequest( @@ -68,6 +69,11 @@ class SearchScraperRequest(BaseModel): mock: bool = Field(default=False, description="Whether to use mock mode for the request") render_heavy_js: bool = Field(default=False, description="Whether to render heavy JavaScript on the page") stealth: bool = Field(default=False, description="Enable stealth mode to avoid bot detection") + location_geo_code: Optional[str] = Field( + None, + description="The geo code of the location to search in", + example="us", + ) @model_validator(mode="after") def validate_user_prompt(self) -> "SearchScraperRequest":