Skip to content

Commit 7381d58

Browse files
author
stlc-bot
committed
feat(scrape): add login profiles for authenticated scraping (#1617)
Stainless-Generated-From: e28e1d16d8f87075395bc8e99fc1698ed9a138df
1 parent 75faef0 commit 7381d58

3 files changed

Lines changed: 59 additions & 0 deletions

File tree

‎src/context/dev/types/web_scrape_params.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
"SharedParamsActionWaitFor",
3232
"SharedParamsParsers",
3333
"SharedParamsParsersPdf",
34+
"SharedParamsProfile",
35+
"SharedParamsProfileExisting",
36+
"SharedParamsProfileNew",
3437
"SharedParamsViewport",
3538
"TimeoutOpts",
3639
]
@@ -309,6 +312,28 @@ class SharedParamsParsers(TypedDict, total=False):
309312
"""PDF page range and OCR."""
310313

311314

315+
class SharedParamsProfileExisting(TypedDict, total=False):
316+
profile_id: Required[Annotated[str, PropertyInfo(alias="profileId")]]
317+
"""The ID returned in profile.id by an earlier scrape."""
318+
319+
type: Required[Literal["existing"]]
320+
"""Reuse a saved browser profile."""
321+
322+
323+
class SharedParamsProfileNew(TypedDict, total=False):
324+
identifier: Required[str]
325+
"""Username or email for the target website."""
326+
327+
password: Required[str]
328+
"""Password used to sign in. It is never stored in the profile."""
329+
330+
type: Required[Literal["new"]]
331+
"""Sign in and create a browser profile."""
332+
333+
334+
SharedParamsProfile: TypeAlias = Union[SharedParamsProfileExisting, SharedParamsProfileNew]
335+
336+
312337
class SharedParamsViewport(TypedDict, total=False):
313338
"""Browser size in pixels.
314339
@@ -361,6 +386,13 @@ class SharedParams(TypedDict, total=False):
361386
parsers: SharedParamsParsers
362387
"""Document parsing options."""
363388

389+
profile: SharedParamsProfile
390+
"""Create or reuse an authenticated browser profile.
391+
392+
Requires a paid plan and an HTTPS target. Profiles persist session state, bypass
393+
shared caches, and cannot be combined with ZDR, custom headers, or raw bytes.
394+
"""
395+
364396
settle_animations: Annotated[bool, PropertyInfo(alias="settleAnimations")]
365397
"""Wait for CSS animations to finish before capture.
366398

‎src/context/dev/types/web_scrape_response.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"ProductData",
2727
"ProductDataProduct",
2828
"ProductDataProductVariant",
29+
"Profile",
2930
"Screenshot",
3031
"KeyMetadata",
3132
]
@@ -385,6 +386,18 @@ class Product(BaseModel):
385386
"""Explanation of the failure and possible next steps."""
386387

387388

389+
class Profile(BaseModel):
390+
"""
391+
Authenticated browser profile used for this scrape, or null when no profile was requested. New and existing profile requests both return the profile ID.
392+
"""
393+
394+
id: str
395+
"""
396+
Save this ID after creating a profile, then reuse it as
397+
sharedParams.profile.profileId with type "existing".
398+
"""
399+
400+
388401
class Screenshot(BaseModel):
389402
"""Screenshot as a base64 image data URL."""
390403

@@ -449,6 +462,12 @@ class WebScrapeResponse(BaseModel):
449462
product: Product
450463
"""Product details found on the page."""
451464

465+
profile: Optional[Profile] = None
466+
"""
467+
Authenticated browser profile used for this scrape, or null when no profile was
468+
requested. New and existing profile requests both return the profile ID.
469+
"""
470+
452471
request_id: str
453472
"""Unique ID of this request, also in `X-Request-Id`.
454473

‎tests/api_resources/test_web.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,10 @@ def test_method_scrape_with_all_params(self, client: ContextDev) -> None:
312312
"start_page": 1,
313313
}
314314
},
315+
"profile": {
316+
"profile_id": "prof_210b9798eb53baa4e69d31c1071cf03d",
317+
"type": "existing",
318+
},
315319
"settle_animations": True,
316320
"theme": "light",
317321
"viewport": {
@@ -854,6 +858,10 @@ async def test_method_scrape_with_all_params(self, async_client: AsyncContextDev
854858
"start_page": 1,
855859
}
856860
},
861+
"profile": {
862+
"profile_id": "prof_210b9798eb53baa4e69d31c1071cf03d",
863+
"type": "existing",
864+
},
857865
"settle_animations": True,
858866
"theme": "light",
859867
"viewport": {

0 commit comments

Comments
 (0)