Skip to content

Commit

Permalink
docs: enhance README with examples for searching and downloading imag…
Browse files Browse the repository at this point in the history
…es using API
  • Loading branch information
sean1832 committed Jan 16, 2025
1 parent eee31d1 commit 635a2c0
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ pinterest-dl download [url_list] [options]
You can also use the `PinterestDL` class directly in your Python code to scrape and download images programmatically.

### 1. Quick Scrape and Download
The following example shows how to scrape and download images from a Pinterest URL in one step.
This example shows how to **scrape** and download images from a Pinterest URL in one step.

```python
from pinterest_dl import PinterestDL
Expand All @@ -197,6 +197,27 @@ images = PinterestDL.with_api(
)
```

This example shows how to **search** with query and download images from a Pinterest URL in one step.

```python
from pinterest_dl import PinterestDL

# Initialize and run the Pinterest image downloader with specified settings
# `search_and_download` is only available in API mode
images = PinterestDL.with_api(
timeout=3, # Timeout in seconds for each request (default: 3)
verbose=False, # Enable detailed logging for debugging (default: False)
).search_and_download(
query="art", # Pinterest search query
output_dir="images/art", # Directory to save downloaded images
limit=30, # Max number of images to download
min_resolution=(512, 512), # Minimum resolution for images (width, height) (default: None)
json_output="art.json", # File to save URLs of scraped images (default: None)
dry_run=False, # If True, performs a scrape without downloading images (default: False)
add_captions=True, # Adds image `alt` text as metadata to images (default: False)
)
```

### 2. Scrape with Cookies for Private Boards
**2a. Obtain cookies**
You need to first log in to Pinterest to obtain browser cookies for scraping private boards and pins.
Expand Down Expand Up @@ -252,6 +273,8 @@ images = (
Use this example if you need more granular control over scraping and downloading images.

#### 3a. With API

##### Scrape Images
```python
import json

Expand Down Expand Up @@ -281,6 +304,21 @@ valid_indices = list(range(len(downloaded_imgs))) # All images are valid to add
PinterestDL.add_captions(images=downloaded_imgs, indices=valid_indices)
```

##### Search Images
```python
import json
from pinterest_dl import PinterestDL

# 1. Initialize PinterestDL with API.
scraped_images = PinterestDL.with_api().search(
query="art", # Search query for Pinterest
limit=30, # Maximum number of images to scrape
min_resolution=(512, 512), # Minimum resolution for images
delay=0.4, # Delay between requests (default: 0.2)
)
# ... (Same as above)
```

#### 3b. With Browser
```python
import json
Expand Down

0 comments on commit 635a2c0

Please sign in to comment.