docs: update docs to add file downloading examples
This commit is contained in:
@@ -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.
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user