|
11 | 11 | from json.decoder import JSONDecodeError
|
12 | 12 | from ..core.api_error import ApiError
|
13 | 13 | from ..types.browser_get_cdp_url_response import BrowserGetCdpUrlResponse
|
| 14 | +from ..types.browser_get_current_url_response import BrowserGetCurrentUrlResponse |
14 | 15 | from ..types.save_browser_auth_response import SaveBrowserAuthResponse
|
15 | 16 | from ..types.modify_browser_auth_response import ModifyBrowserAuthResponse
|
16 | 17 | from ..types.browser_authenticate_response import BrowserAuthenticateResponse
|
@@ -134,6 +135,62 @@ def get_cdp_url(
|
134 | 135 | raise ApiError(status_code=_response.status_code, body=_response.text)
|
135 | 136 | raise ApiError(status_code=_response.status_code, body=_response_json)
|
136 | 137 |
|
| 138 | + def get_current_url( |
| 139 | + self, instance_id: str, *, request_options: typing.Optional[RequestOptions] = None |
| 140 | + ) -> BrowserGetCurrentUrlResponse: |
| 141 | + """ |
| 142 | + Parameters |
| 143 | + ---------- |
| 144 | + instance_id : str |
| 145 | +
|
| 146 | + request_options : typing.Optional[RequestOptions] |
| 147 | + Request-specific configuration. |
| 148 | +
|
| 149 | + Returns |
| 150 | + ------- |
| 151 | + BrowserGetCurrentUrlResponse |
| 152 | + Successful Response |
| 153 | +
|
| 154 | + Examples |
| 155 | + -------- |
| 156 | + from scrapybara import Scrapybara |
| 157 | +
|
| 158 | + client = Scrapybara( |
| 159 | + api_key="YOUR_API_KEY", |
| 160 | + ) |
| 161 | + client.browser.get_current_url( |
| 162 | + instance_id="instance_id", |
| 163 | + ) |
| 164 | + """ |
| 165 | + _response = self._client_wrapper.httpx_client.request( |
| 166 | + f"v1/instance/{jsonable_encoder(instance_id)}/browser/current_url", |
| 167 | + method="GET", |
| 168 | + request_options=request_options, |
| 169 | + ) |
| 170 | + try: |
| 171 | + if 200 <= _response.status_code < 300: |
| 172 | + return typing.cast( |
| 173 | + BrowserGetCurrentUrlResponse, |
| 174 | + parse_obj_as( |
| 175 | + type_=BrowserGetCurrentUrlResponse, # type: ignore |
| 176 | + object_=_response.json(), |
| 177 | + ), |
| 178 | + ) |
| 179 | + if _response.status_code == 422: |
| 180 | + raise UnprocessableEntityError( |
| 181 | + typing.cast( |
| 182 | + HttpValidationError, |
| 183 | + parse_obj_as( |
| 184 | + type_=HttpValidationError, # type: ignore |
| 185 | + object_=_response.json(), |
| 186 | + ), |
| 187 | + ) |
| 188 | + ) |
| 189 | + _response_json = _response.json() |
| 190 | + except JSONDecodeError: |
| 191 | + raise ApiError(status_code=_response.status_code, body=_response.text) |
| 192 | + raise ApiError(status_code=_response.status_code, body=_response_json) |
| 193 | + |
137 | 194 | def save_auth(
|
138 | 195 | self,
|
139 | 196 | instance_id: str,
|
@@ -518,6 +575,70 @@ async def main() -> None:
|
518 | 575 | raise ApiError(status_code=_response.status_code, body=_response.text)
|
519 | 576 | raise ApiError(status_code=_response.status_code, body=_response_json)
|
520 | 577 |
|
| 578 | + async def get_current_url( |
| 579 | + self, instance_id: str, *, request_options: typing.Optional[RequestOptions] = None |
| 580 | + ) -> BrowserGetCurrentUrlResponse: |
| 581 | + """ |
| 582 | + Parameters |
| 583 | + ---------- |
| 584 | + instance_id : str |
| 585 | +
|
| 586 | + request_options : typing.Optional[RequestOptions] |
| 587 | + Request-specific configuration. |
| 588 | +
|
| 589 | + Returns |
| 590 | + ------- |
| 591 | + BrowserGetCurrentUrlResponse |
| 592 | + Successful Response |
| 593 | +
|
| 594 | + Examples |
| 595 | + -------- |
| 596 | + import asyncio |
| 597 | +
|
| 598 | + from scrapybara import AsyncScrapybara |
| 599 | +
|
| 600 | + client = AsyncScrapybara( |
| 601 | + api_key="YOUR_API_KEY", |
| 602 | + ) |
| 603 | +
|
| 604 | +
|
| 605 | + async def main() -> None: |
| 606 | + await client.browser.get_current_url( |
| 607 | + instance_id="instance_id", |
| 608 | + ) |
| 609 | +
|
| 610 | +
|
| 611 | + asyncio.run(main()) |
| 612 | + """ |
| 613 | + _response = await self._client_wrapper.httpx_client.request( |
| 614 | + f"v1/instance/{jsonable_encoder(instance_id)}/browser/current_url", |
| 615 | + method="GET", |
| 616 | + request_options=request_options, |
| 617 | + ) |
| 618 | + try: |
| 619 | + if 200 <= _response.status_code < 300: |
| 620 | + return typing.cast( |
| 621 | + BrowserGetCurrentUrlResponse, |
| 622 | + parse_obj_as( |
| 623 | + type_=BrowserGetCurrentUrlResponse, # type: ignore |
| 624 | + object_=_response.json(), |
| 625 | + ), |
| 626 | + ) |
| 627 | + if _response.status_code == 422: |
| 628 | + raise UnprocessableEntityError( |
| 629 | + typing.cast( |
| 630 | + HttpValidationError, |
| 631 | + parse_obj_as( |
| 632 | + type_=HttpValidationError, # type: ignore |
| 633 | + object_=_response.json(), |
| 634 | + ), |
| 635 | + ) |
| 636 | + ) |
| 637 | + _response_json = _response.json() |
| 638 | + except JSONDecodeError: |
| 639 | + raise ApiError(status_code=_response.status_code, body=_response.text) |
| 640 | + raise ApiError(status_code=_response.status_code, body=_response_json) |
| 641 | + |
521 | 642 | async def save_auth(
|
522 | 643 | self,
|
523 | 644 | instance_id: str,
|
|
0 commit comments