Capturing a Download
The capture_download function captures downloads triggered by clicking an element, storing them for further use.
Features
-
Handles File Downloads: Supports PDFs, images, and other document types.
-
Allows Filename Customization: Override file names if needed.
-
Automatically Stores Files: Saves the downloaded content locally.
Parameters
-
clickable
** (ElementHandle
)**: The element triggering the download. -
override_filename
** (Optional[str]
)**: Custom filename for the downloaded file. -
override_url
** (Optional[str]
)**: Custom download URL. -
timeout
float | None
Returns
-
DownloadMeta
: Metadata about the captured file.
Usage
async def scrape(
sdk: SDK, current_url: str, context: dict[str, Any], *args: Any, **kwargs: Any
) -> None:
button = await sdk.page.query_selector("button.download")
download_meta = await sdk.capture_download(download_button,timeout=10000 )
data = {'url': download_metadata}
await sdk.save_data(data)