From 026161c8f8b6198dc8aeb7adf40743f5230ca3c7 Mon Sep 17 00:00:00 2001 From: Karim shoair Date: Mon, 10 Nov 2025 03:02:41 +0200 Subject: [PATCH] docs: update docs to add file downloading examples --- docs/fetching/choosing.md | 3 +-- docs/fetching/dynamic.md | 11 +++++++++++ docs/fetching/static.md | 10 ++++++++++ docs/fetching/stealthy.md | 11 +++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/docs/fetching/choosing.md b/docs/fetching/choosing.md index 37b9c8c..50ddf37 100644 --- a/docs/fetching/choosing.md +++ b/docs/fetching/choosing.md @@ -71,8 +71,7 @@ The `Response` object is the same as the [Selector](../parsing/main_classes.md#s >>> page.headers # Response headers >>> page.request_headers # Request headers >>> page.history # Response history of redirections, if any ->>> page.body # Raw HTML response body without any processing ->>> page.raw_response # Raw response of the last request made by the browser, if any (Useful for downloading binary files and text/json files) +>>> page.body # Raw response body without any processing >>> page.encoding # Response encoding ``` All fetchers return the `Response` object. \ No newline at end of file diff --git a/docs/fetching/dynamic.md b/docs/fetching/dynamic.md index 421dcbe..066d12c 100644 --- a/docs/fetching/dynamic.md +++ b/docs/fetching/dynamic.md @@ -131,6 +131,17 @@ page = DynamicFetcher.fetch( ) ``` +### Downloading Files + +```python +page = DynamicFetcher.fetch('https://raw.githubusercontent.com/D4Vinci/Scrapling/main/images/poster.png') + +with open(file='poster.png', mode='wb') as f: + f.write(page.body) +``` + +The `body` attribute of the `Response` object is a `bytes` object containing the response body in case of Non-HTML responses. + ### Browser Automation This is where your knowledge about [Playwright's Page API](https://playwright.dev/python/docs/api/class-page) comes into play. The function you pass here takes the page object from Playwright's API, performs the desired action, and then the fetcher continues. diff --git a/docs/fetching/static.md b/docs/fetching/static.md index efd5717..43a2d0e 100644 --- a/docs/fetching/static.md +++ b/docs/fetching/static.md @@ -269,6 +269,16 @@ def scrape_products(): return results ``` +### Downloading Files + +```python +from scrapling.fetchers import Fetcher + +page = Fetcher.get('https://raw.githubusercontent.com/D4Vinci/Scrapling/main/images/poster.png') +with open(file='poster.png', mode='wb') as f: + f.write(page.body) +``` + ### Pagination Handling ```python diff --git a/docs/fetching/stealthy.md b/docs/fetching/stealthy.md index 9e11993..d53e930 100644 --- a/docs/fetching/stealthy.md +++ b/docs/fetching/stealthy.md @@ -152,6 +152,17 @@ page = StealthyFetcher.fetch( ) ``` +### Downloading Files + +```python +page = StealthyFetcher.fetch('https://raw.githubusercontent.com/D4Vinci/Scrapling/main/images/poster.png') + +with open(file='poster.png', mode='wb') as f: + f.write(page.body) +``` + +The `body` attribute of the `Response` object is a `bytes` object containing the response body in case of Non-HTML responses. + ### Browser Automation This is where your knowledge about [Playwright's Page API](https://playwright.dev/python/docs/api/class-page) comes into play. The function you pass here takes the page object from Playwright's API, performs the desired action, and then the fetcher continues.