Skip to content

Commit 4a08a96

Browse files
VinciGit00claude
andcommitted
feat: add location_geo_code parameter to SearchScraper for geo-targeting
Add optional geo-targeting to Google search for SearchScraper: - Add location_geo_code field to SearchScraperRequest model - Update sync client searchscraper method to accept location_geo_code - Update async client searchscraper method to accept location_geo_code This enables filtering search results by geographic location using country codes like 'us', 'uk', 'de'. Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent bfc7246 commit 4a08a96

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

scrapegraph-py/src/async_client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ async def searchscraper(
782782
output_schema: Optional[BaseModel] = None,
783783
extraction_mode: bool = True,
784784
stealth: bool = False,
785+
location_geo_code: Optional[str] = None,
785786
return_toon: bool = False,
786787
):
787788
"""Send a searchscraper request
@@ -797,6 +798,7 @@ async def searchscraper(
797798
extraction_mode: Whether to use AI extraction (True) or markdown conversion (False).
798799
AI extraction costs 10 credits per page, markdown conversion costs 2 credits per page.
799800
stealth: Enable stealth mode to avoid bot detection
801+
location_geo_code: The geo code of the location to search in (e.g., 'us', 'uk', 'de')
800802
return_toon: If True, return response in TOON format (reduces token usage by 30-60%)
801803
"""
802804
logger.info("🔍 Starting searchscraper request")
@@ -807,6 +809,8 @@ async def searchscraper(
807809
logger.debug("🔧 Using custom headers")
808810
if stealth:
809811
logger.debug("🥷 Stealth mode enabled")
812+
if location_geo_code:
813+
logger.debug(f"🌍 Location geo code: {location_geo_code}")
810814
if return_toon:
811815
logger.debug("🎨 TOON format output enabled")
812816

@@ -817,6 +821,7 @@ async def searchscraper(
817821
output_schema=output_schema,
818822
extraction_mode=extraction_mode,
819823
stealth=stealth,
824+
location_geo_code=location_geo_code,
820825
)
821826
logger.debug("✅ Request validation passed")
822827

scrapegraph-py/src/client.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -790,8 +790,9 @@ def searchscraper(
790790
headers: Optional[dict[str, str]] = None,
791791
output_schema: Optional[BaseModel] = None,
792792
extraction_mode: bool = True,
793-
mock: bool=False,
794-
stealth: bool=False,
793+
mock: bool = False,
794+
stealth: bool = False,
795+
location_geo_code: Optional[str] = None,
795796
return_toon: bool = False,
796797
):
797798
"""Send a searchscraper request
@@ -808,6 +809,7 @@ def searchscraper(
808809
AI extraction costs 10 credits per page, markdown conversion costs 2 credits per page.
809810
mock: Enable mock mode for testing
810811
stealth: Enable stealth mode to avoid bot detection
812+
location_geo_code: The geo code of the location to search in (e.g., 'us', 'uk', 'de')
811813
return_toon: If True, return response in TOON format (reduces token usage by 30-60%)
812814
"""
813815
logger.info("🔍 Starting searchscraper request")
@@ -818,6 +820,8 @@ def searchscraper(
818820
logger.debug("🔧 Using custom headers")
819821
if stealth:
820822
logger.debug("🥷 Stealth mode enabled")
823+
if location_geo_code:
824+
logger.debug(f"🌍 Location geo code: {location_geo_code}")
821825
if return_toon:
822826
logger.debug("🎨 TOON format output enabled")
823827

@@ -828,7 +832,8 @@ def searchscraper(
828832
output_schema=output_schema,
829833
extraction_mode=extraction_mode,
830834
mock=mock,
831-
stealth=stealth
835+
stealth=stealth,
836+
location_geo_code=location_geo_code,
832837
)
833838
logger.debug("✅ Request validation passed")
834839

scrapegraph-py/src/models/searchscraper.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ class SearchScraperRequest(BaseModel):
6868
mock: bool = Field(default=False, description="Whether to use mock mode for the request")
6969
render_heavy_js: bool = Field(default=False, description="Whether to render heavy JavaScript on the page")
7070
stealth: bool = Field(default=False, description="Enable stealth mode to avoid bot detection")
71+
location_geo_code: Optional[str] = Field(
72+
default=None,
73+
description="The geo code of the location to search in (e.g., 'us', 'uk', 'de')",
74+
example="us",
75+
)
7176

7277
@model_validator(mode="after")
7378
def validate_user_prompt(self) -> "SearchScraperRequest":

0 commit comments

Comments
 (0)