Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "scrapybara"

[tool.poetry]
name = "scrapybara"
version = "2.3.5"
version = "2.3.6"
description = ""
readme = "README.md"
authors = []
Expand Down
64 changes: 64 additions & 0 deletions reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ client.start()
<dl>
<dd>

**blocked_domains:** `typing.Optional[typing.Sequence[str]]`

</dd>
</dl>

<dl>
<dd>

**request_options:** `typing.Optional[RequestOptions]` — Request-specific configuration.

</dd>
Expand Down Expand Up @@ -861,6 +869,62 @@ client.browser.get_cdp_url(
</dl>


</dd>
</dl>
</details>

<details><summary><code>client.browser.<a href="src/scrapybara/browser/client.py">get_current_url</a>(...)</code></summary>
<dl>
<dd>

#### 🔌 Usage

<dl>
<dd>

<dl>
<dd>

```python
from scrapybara import Scrapybara

client = Scrapybara(
api_key="YOUR_API_KEY",
)
client.browser.get_current_url(
instance_id="instance_id",
)

```
</dd>
</dl>
</dd>
</dl>

#### ⚙️ Parameters

<dl>
<dd>

<dl>
<dd>

**instance_id:** `str`

</dd>
</dl>

<dl>
<dd>

**request_options:** `typing.Optional[RequestOptions]` — Request-specific configuration.

</dd>
</dl>
</dd>
</dl>


</dd>
</dl>
</details>
Expand Down
2 changes: 2 additions & 0 deletions src/scrapybara/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
BashResponse,
BrowserAuthenticateResponse,
BrowserGetCdpUrlResponse,
BrowserGetCurrentUrlResponse,
Button,
CellType,
ClickMouseAction,
Expand Down Expand Up @@ -67,6 +68,7 @@
"BashResponse",
"BrowserAuthenticateResponse",
"BrowserGetCdpUrlResponse",
"BrowserGetCurrentUrlResponse",
"Button",
"CellType",
"ClickMouseAction",
Expand Down
8 changes: 8 additions & 0 deletions src/scrapybara/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def start(
*,
instance_type: typing.Optional[DeploymentConfigInstanceType] = OMIT,
timeout_hours: typing.Optional[float] = OMIT,
blocked_domains: typing.Optional[typing.Sequence[str]] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> GetInstanceResponse:
"""
Expand All @@ -116,6 +117,8 @@ def start(

timeout_hours : typing.Optional[float]

blocked_domains : typing.Optional[typing.Sequence[str]]

request_options : typing.Optional[RequestOptions]
Request-specific configuration.

Expand All @@ -139,6 +142,7 @@ def start(
json={
"instance_type": instance_type,
"timeout_hours": timeout_hours,
"blocked_domains": blocked_domains,
},
headers={
"content-type": "application/json",
Expand Down Expand Up @@ -383,6 +387,7 @@ async def start(
*,
instance_type: typing.Optional[DeploymentConfigInstanceType] = OMIT,
timeout_hours: typing.Optional[float] = OMIT,
blocked_domains: typing.Optional[typing.Sequence[str]] = OMIT,
request_options: typing.Optional[RequestOptions] = None,
) -> GetInstanceResponse:
"""
Expand All @@ -392,6 +397,8 @@ async def start(

timeout_hours : typing.Optional[float]

blocked_domains : typing.Optional[typing.Sequence[str]]

request_options : typing.Optional[RequestOptions]
Request-specific configuration.

Expand Down Expand Up @@ -423,6 +430,7 @@ async def main() -> None:
json={
"instance_type": instance_type,
"timeout_hours": timeout_hours,
"blocked_domains": blocked_domains,
},
headers={
"content-type": "application/json",
Expand Down
121 changes: 121 additions & 0 deletions src/scrapybara/browser/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from json.decoder import JSONDecodeError
from ..core.api_error import ApiError
from ..types.browser_get_cdp_url_response import BrowserGetCdpUrlResponse
from ..types.browser_get_current_url_response import BrowserGetCurrentUrlResponse
from ..types.save_browser_auth_response import SaveBrowserAuthResponse
from ..types.modify_browser_auth_response import ModifyBrowserAuthResponse
from ..types.browser_authenticate_response import BrowserAuthenticateResponse
Expand Down Expand Up @@ -134,6 +135,62 @@ def get_cdp_url(
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)

def get_current_url(
self, instance_id: str, *, request_options: typing.Optional[RequestOptions] = None
) -> BrowserGetCurrentUrlResponse:
"""
Parameters
----------
instance_id : str

request_options : typing.Optional[RequestOptions]
Request-specific configuration.

Returns
-------
BrowserGetCurrentUrlResponse
Successful Response

Examples
--------
from scrapybara import Scrapybara

client = Scrapybara(
api_key="YOUR_API_KEY",
)
client.browser.get_current_url(
instance_id="instance_id",
)
"""
_response = self._client_wrapper.httpx_client.request(
f"v1/instance/{jsonable_encoder(instance_id)}/browser/current_url",
method="GET",
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
return typing.cast(
BrowserGetCurrentUrlResponse,
parse_obj_as(
type_=BrowserGetCurrentUrlResponse, # type: ignore
object_=_response.json(),
),
)
if _response.status_code == 422:
raise UnprocessableEntityError(
typing.cast(
HttpValidationError,
parse_obj_as(
type_=HttpValidationError, # type: ignore
object_=_response.json(),
),
)
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)

def save_auth(
self,
instance_id: str,
Expand Down Expand Up @@ -518,6 +575,70 @@ async def main() -> None:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)

async def get_current_url(
self, instance_id: str, *, request_options: typing.Optional[RequestOptions] = None
) -> BrowserGetCurrentUrlResponse:
"""
Parameters
----------
instance_id : str

request_options : typing.Optional[RequestOptions]
Request-specific configuration.

Returns
-------
BrowserGetCurrentUrlResponse
Successful Response

Examples
--------
import asyncio

from scrapybara import AsyncScrapybara

client = AsyncScrapybara(
api_key="YOUR_API_KEY",
)


async def main() -> None:
await client.browser.get_current_url(
instance_id="instance_id",
)


asyncio.run(main())
"""
_response = await self._client_wrapper.httpx_client.request(
f"v1/instance/{jsonable_encoder(instance_id)}/browser/current_url",
method="GET",
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
return typing.cast(
BrowserGetCurrentUrlResponse,
parse_obj_as(
type_=BrowserGetCurrentUrlResponse, # type: ignore
object_=_response.json(),
),
)
if _response.status_code == 422:
raise UnprocessableEntityError(
typing.cast(
HttpValidationError,
parse_obj_as(
type_=HttpValidationError, # type: ignore
object_=_response.json(),
),
)
)
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)

async def save_auth(
self,
instance_id: str,
Expand Down
Loading
Loading