pinterest-dl


Namepinterest-dl JSON
Version 0.3.2 PyPI version JSON
download
home_pageNone
SummaryAn unofficial Pinterest image downloader
upload_time2024-12-14 04:52:06
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseApache-2.0
keywords pinterest image downloader selenium web scraping
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Pinterest Image Downloader (pinterest-dl)
[![PyPI - Version](https://img.shields.io/pypi/v/pinterest-dl)](https://pypi.org/project/pinterest-dl/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pinterest-dl)](https://pypi.org/project/pinterest-dl/)
[![PyPI - License](https://img.shields.io/pypi/l/pinterest-dl)](https://github.com/sean1832/pinterest-dl/blob/main/LICENSE)
[![Downloads](https://static.pepy.tech/badge/pinterest-dl)](https://pepy.tech/project/pinterest-dl)


This library facilitates the scraping and downloading of images from [Pinterest](https://pinterest.com). Using [Selenium](https://selenium.dev) for automation, it enables users to extract images from a specified Pinterest URL and save them to a chosen directory.

It includes a [CLI](#-cli-usage) for direct usage and a [Python API](#️-python-api) for programmatic access. The tool supports scraping images from public and private boards and pins using browser cookies. It also allows users to save scraped URLs to a JSON file for future access.

> **⚠️ Disclaimer:**  
> This project is independent and not affiliated with Pinterest. It's designed solely for educational purposes. Please be aware that automating the scraping of websites might conflict with their [Terms of Service](https://developers.pinterest.com/terms/). The repository owner disclaims any liability for misuse of this tool. Use it responsibly and at your own legal risk.

> **🗒️ Note:**  
> This project draws inspiration from [pinterest-image-scraper](https://github.com/xjdeng/pinterest-image-scraper).

## 🌟 Features
- ✅ Scrape images directly from a Pinterest URL.
- ✅ Asynchronously download images from a list of URLs. ([#1](https://github.com/sean1832/pinterest-dl/pull/1))
- ✅ Save scraped URLs to a JSON file for future access.
- ✅ Incognito mode to keep your scraping discreet.
- ✅ Access detailed output for effective debugging.
- ✅ Support for the Firefox browser.
- ✅ Insert `alt` text for images as metadata `comment` in the downloaded image for searchability.
- ✅ Scrape private boards and pins with browser cookies. ([#20](https://github.com/sean1832/pinterest-dl/pull/20))
- ✅ Scrape images using reversed engineered Pinterest API. (This will be default behaviour. You can use webdriver by specifying `--client chrome` or `--client firefox`) ([#21](https://github.com/sean1832/pinterest-dl/pull/21))

## 🚩 Known Issues
- ~~🔲 Incompatibility with Pinterest URLs that include search queries.~~ Implemented `search` command since `v0.3.0`. ([#23](https://github.com/sean1832/pinterest-dl/pull/23))
- 🔲 Not sorely tested on Linux and Mac. Please create an [Issue](https://github.com/sean1832/pinterest-dl/issues) to report any bugs.

## 📋 Requirements
- Python 3.10 or newer
- Chrome or Firefox browser

## 📥 Installation

### Using pip (Recommended)
```bash
pip install pinterest-dl
```

### Cloning from GitHub
```bash
git clone https://github.com/sean1832/pinterest-dl.git
cd pinterest-dl
pip install .
```

## 🚀 CLI-Usage

### General Command Structure
```bash
pinterest-dl [command] [options]
```

---
### Examples

**Scraping Images in anonymous mode:**

Scrape images in anonymous mode, without login, to the `./images/art` directory from the Pinterest URL `https://www.pinterest.com/pin/1234567` with a limit of `30` images and a minimum resolution of `512x512`. Save scraped URLs to a `JSON` file.
```bash
pinterest-dl scrape "https://www.pinterest.com/pin/1234567" "images/art" -l 30 -r 512x512 --json
```

**Get Browser Cookies:**

Get browser cookies for Pinterest login and save them to the `cookies.json` file in headful mode (with browser window).
```bash
pinterest-dl login -o cookies.json --headful
```
> [!TIP]
> You will be prompted to enter your Pinterest email and password. The tool will save the browser cookies to the specified file for future use.

**Scraping Private Boards:**

Scrape images from a private Pinterest board using the cookies saved in the `cookies.json` file.
```bash
pinterest-dl scrape "https://www.pinterest.com/pin/1234567" "images/art" -l 30 -c cookies.json
```

> [!TIP]
> You can use the `--client` option to use `chrome` or `firefox` Webdriver for scraping. This is slower but more reliable.
> It will open a browser in headless mode to scrape images. You can also use the `--headful` flag to run the browser in windowed mode.

**Downloading Images:**

Download images from the `art.json` file to the `./downloaded_imgs` directory with a minimum resolution of `1024x1024`.
```bash
pinterest-dl download art.json -o downloaded_imgs -r 1024x1024
```
---
### Commands

#### 1. Login
Login to Pinterest using your credentials to obtain browser cookies for scraping private boards and pins.

**Syntax:**
```bash
pinterest-dl login [options]
```

![login](/doc/images/pinterest-dl-login.gif)

**Options:**
- `-o`, `--output [file]`: File to save browser cookies for future use. (default: `cookies.json`)
- `--client`: Choose the scraping client (`chrome` / `firefox`). (default: `chrome`)
- `--headful`: Run in headful mode with browser window.
- `--verbose`: Enable detailed output for debugging.
- `--incognito`: Activate incognito mode for scraping.

> [!TIP]
> After entering `login` command, you will be prompted to enter your Pinterest email and password.
> The tool will then save the browser cookies to the specified file for future use. (if not specified, it will save to `./cookies.json`)

#### 2. Scrape
Extract images from a specified Pinterest URL.

**Syntax:**
```bash
pinterest-dl scrape [url] [output_dir] [options]
```

![scrape](/doc/images/pinterest-dl-scrape.gif)

**Options:**

- `-c`, `--cookies [file]`: File containing browser cookies for private boards/pins. Run `login` command to obtain cookies.
- `-l`, `--limit [number]`: Max number of image to download (default: 100).
- `-r`, `--resolution [width]x[height]`: Minimum image resolution for download (e.g., 512x512).
- `--timeout [second]`: Timeout in seconds for requests (default: 3).
- `--json`: Save scraped URLs to a JSON file.
- `--dry-run`: Execute scrape without downloading images.
- `--verbose`: Enable detailed output for debugging.
- `--client`: Choose the scraping client (`api` / `chrome` / `firefox`). (default: api)
- `--incognito`: Activate incognito mode for scraping. (*chrome / firefox only*)
- `--headful`: Run in headful mode with browser window. (*chrome / firefox only*)

#### 3. Search
Search for images on Pinterest using a query. (*Experimental, currently only available in API mode*)

**Syntax:**
```bash
pinterest-dl search [query] [output_dir] [options]
```

![search](/doc/images/pinterest-dl-search.gif)

**Options:**
- `-c`, `--cookies [file]`: File containing browser cookies for private boards/pins. Run `login` command to obtain cookies.
- `-l`, `--limit [number]`: Max number of image to download (default: 100).
- `-r`, `--resolution [width]x[height]`: Minimum image resolution for download (e.g., 512x512).
- `--timeout [second]`: Timeout in seconds for requests (default: 3).
- `--json`: Save scraped URLs to a JSON file.
- `--dry-run`: Execute scrape without downloading images.
- `--verbose`: Enable detailed output for debugging.

#### 4. Download
Download images from a list of URLs provided in a file.

**Syntax:**
```bash
pinterest-dl download [url_list] [options]
```

![download](/doc/images/pinterest-dl-download.gif)

**Options:**
- `-o`, `--output [directory]`: Output directory (default: ./<json_filename>).
- `-r`, `--resolution [width]x[height]`: minimum resolution to download (e.g. 512x512).
- `--verbose`: Enable verbose output.


## 🛠️ Python API
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.

```python
from pinterest_dl import PinterestDL

# Initialize and run the Pinterest image downloader with specified settings
images = PinterestDL.with_api(
    timeout=3,  # Timeout in seconds for each request (default: 3)
    verbose=False,  # Enable detailed logging for debugging (default: False)
).scrape_and_download(
    url="https://www.pinterest.com/pin/1234567",  # Pinterest URL to scrape
    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.
```python
import os
import json

from pinterest_dl import PinterestDL

# Make sure you don't expose your password in the code.
email = input("Enter Pinterest email: ")
password = os.getenv("PINTEREST_PASSWORD")

# Initialize browser and login to Pinterest
cookies = PinterestDL.with_browser(
    browser_type="chrome",
    headless=True,
).login(email, password).get_cookies(
    after_sec=7,  # Time to wait before capturing cookies. Login may take time.
)

# Save cookies to a file
with open("cookies.json", "w") as f:
    json.dump(cookies, f, indent=4)
```

**2b. Scrape with cookies**
After obtaining cookies, you can use them to scrape private boards and pins.
```python
from pinterest_dl import PinterestDL

# Load cookies from a file
with open("cookies.json", "r") as f:
    cookies = json.load(f)

# Initialize and run the Pinterest image downloader with specified settings
images = (
    PinterestDL.with_api()
    .with_cookies(
        cookies,  # cookies in selenium format
    )
    .scrape_and_download(
        url="https://www.pinterest.com/pin/1234567",  # Assume this is a private board URL
        output_dir="images/art",  # Directory to save downloaded images
        limit=30,  # Max number of images to download
    )
)
```

### 3. Detailed Scraping with Lower-Level Control

Use this example if you need more granular control over scraping and downloading images.

#### 3a. With API
```python
import json

from pinterest_dl import PinterestDL

# 1. Initialize PinterestDL with API.
scraped_images = PinterestDL.with_api().scrape(
    url="https://www.pinterest.com/pin/1234567",  # URL of the Pinterest page
    limit=30,  # Maximum number of images to scrape
    min_resolution=(512, 512),  # <- Only available to set in the API. Browser mode will have to pruned after download.
)

# 2. Save Scraped Data to JSON
# Convert scraped data into a dictionary and save it to a JSON file for future access
images_data = [img.to_dict() for img in scraped_images]
with open("art.json", "w") as f:
    json.dump(images_data, f, indent=4)

# 3. Download Images
# Download images to a specified directory
downloaded_imgs = PinterestDL.download_images(images=scraped_images, output_dir="images/art")

valid_indices = list(range(len(downloaded_imgs)))  # All images are valid to add captions

# 4. Add Alt Text as Metadata
# Extract `alt` text from images and set it as metadata in the downloaded files
PinterestDL.add_captions(images=downloaded_imgs, indices=valid_indices)
```

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

from pinterest_dl import PinterestDL

# 1. Initialize PinterestDL with API.
scraped_images = PinterestDL.with_browser(
    browser_type="chrome",  # Browser type to use ('chrome' or 'firefox')
    headless=True,  # Run browser in headless mode
).scrape(
    url="https://www.pinterest.com/pin/1234567",  # URL of the Pinterest page
    limit=30,  # Maximum number of images to scrape
)

# 2. Save Scraped Data to JSON
# Convert scraped data into a dictionary and save it to a JSON file for future access
images_data = [img.to_dict() for img in scraped_images]
with open("art.json", "w") as f:
    json.dump(images_data, f, indent=4)

# 3. Download Images
# Download images to a specified directory
downloaded_imgs = PinterestDL.download_images(images=scraped_images, output_dir="images/art")

# 4. Prune Images by Resolution
# Remove images that do not meet the minimum resolution criteria
valid_indices = PinterestDL.prune_images(images=downloaded_imgs, min_resolution=(200, 200))

# 5. Add Alt Text as Metadata
# Extract `alt` text from images and set it as metadata in the downloaded files
PinterestDL.add_captions(images=downloaded_imgs, indices=valid_indices)
```

## 📜 License
[Apache License 2.0](LICENSE)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pinterest-dl",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "pinterest, image downloader, selenium, web scraping",
    "author": null,
    "author_email": "sean1832 <dev@zekezhang.com>",
    "download_url": "https://files.pythonhosted.org/packages/61/f1/af423b9e31a2a8adc4295288294b2828bb0b7d4b0ee29d87db8c08b08fa9/pinterest_dl-0.3.2.tar.gz",
    "platform": null,
    "description": "# Pinterest Image Downloader (pinterest-dl)\r\n[![PyPI - Version](https://img.shields.io/pypi/v/pinterest-dl)](https://pypi.org/project/pinterest-dl/)\r\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pinterest-dl)](https://pypi.org/project/pinterest-dl/)\r\n[![PyPI - License](https://img.shields.io/pypi/l/pinterest-dl)](https://github.com/sean1832/pinterest-dl/blob/main/LICENSE)\r\n[![Downloads](https://static.pepy.tech/badge/pinterest-dl)](https://pepy.tech/project/pinterest-dl)\r\n\r\n\r\nThis library facilitates the scraping and downloading of images from [Pinterest](https://pinterest.com). Using [Selenium](https://selenium.dev) for automation, it enables users to extract images from a specified Pinterest URL and save them to a chosen directory.\r\n\r\nIt includes a [CLI](#-cli-usage) for direct usage and a [Python API](#\ufe0f-python-api) for programmatic access. The tool supports scraping images from public and private boards and pins using browser cookies. It also allows users to save scraped URLs to a JSON file for future access.\r\n\r\n> **\u26a0\ufe0f Disclaimer:**  \r\n> This project is independent and not affiliated with Pinterest. It's designed solely for educational purposes. Please be aware that automating the scraping of websites might conflict with their [Terms of Service](https://developers.pinterest.com/terms/). The repository owner disclaims any liability for misuse of this tool. Use it responsibly and at your own legal risk.\r\n\r\n> **\ud83d\uddd2\ufe0f Note:**  \r\n> This project draws inspiration from [pinterest-image-scraper](https://github.com/xjdeng/pinterest-image-scraper).\r\n\r\n## \ud83c\udf1f Features\r\n- \u2705 Scrape images directly from a Pinterest URL.\r\n- \u2705 Asynchronously download images from a list of URLs. ([#1](https://github.com/sean1832/pinterest-dl/pull/1))\r\n- \u2705 Save scraped URLs to a JSON file for future access.\r\n- \u2705 Incognito mode to keep your scraping discreet.\r\n- \u2705 Access detailed output for effective debugging.\r\n- \u2705 Support for the Firefox browser.\r\n- \u2705 Insert `alt` text for images as metadata `comment` in the downloaded image for searchability.\r\n- \u2705 Scrape private boards and pins with browser cookies. ([#20](https://github.com/sean1832/pinterest-dl/pull/20))\r\n- \u2705 Scrape images using reversed engineered Pinterest API. (This will be default behaviour. You can use webdriver by specifying `--client chrome` or `--client firefox`) ([#21](https://github.com/sean1832/pinterest-dl/pull/21))\r\n\r\n## \ud83d\udea9 Known Issues\r\n- ~~\ud83d\udd32 Incompatibility with Pinterest URLs that include search queries.~~ Implemented `search` command since `v0.3.0`. ([#23](https://github.com/sean1832/pinterest-dl/pull/23))\r\n- \ud83d\udd32 Not sorely tested on Linux and Mac. Please create an [Issue](https://github.com/sean1832/pinterest-dl/issues) to report any bugs.\r\n\r\n## \ud83d\udccb Requirements\r\n- Python 3.10 or newer\r\n- Chrome or Firefox browser\r\n\r\n## \ud83d\udce5 Installation\r\n\r\n### Using pip (Recommended)\r\n```bash\r\npip install pinterest-dl\r\n```\r\n\r\n### Cloning from GitHub\r\n```bash\r\ngit clone https://github.com/sean1832/pinterest-dl.git\r\ncd pinterest-dl\r\npip install .\r\n```\r\n\r\n## \ud83d\ude80 CLI-Usage\r\n\r\n### General Command Structure\r\n```bash\r\npinterest-dl [command] [options]\r\n```\r\n\r\n---\r\n### Examples\r\n\r\n**Scraping Images in anonymous mode:**\r\n\r\nScrape images in anonymous mode, without login, to the `./images/art` directory from the Pinterest URL `https://www.pinterest.com/pin/1234567` with a limit of `30` images and a minimum resolution of `512x512`. Save scraped URLs to a `JSON` file.\r\n```bash\r\npinterest-dl scrape \"https://www.pinterest.com/pin/1234567\" \"images/art\" -l 30 -r 512x512 --json\r\n```\r\n\r\n**Get Browser Cookies:**\r\n\r\nGet browser cookies for Pinterest login and save them to the `cookies.json` file in headful mode (with browser window).\r\n```bash\r\npinterest-dl login -o cookies.json --headful\r\n```\r\n> [!TIP]\r\n> You will be prompted to enter your Pinterest email and password. The tool will save the browser cookies to the specified file for future use.\r\n\r\n**Scraping Private Boards:**\r\n\r\nScrape images from a private Pinterest board using the cookies saved in the `cookies.json` file.\r\n```bash\r\npinterest-dl scrape \"https://www.pinterest.com/pin/1234567\" \"images/art\" -l 30 -c cookies.json\r\n```\r\n\r\n> [!TIP]\r\n> You can use the `--client` option to use `chrome` or `firefox` Webdriver for scraping. This is slower but more reliable.\r\n> It will open a browser in headless mode to scrape images. You can also use the `--headful` flag to run the browser in windowed mode.\r\n\r\n**Downloading Images:**\r\n\r\nDownload images from the `art.json` file to the `./downloaded_imgs` directory with a minimum resolution of `1024x1024`.\r\n```bash\r\npinterest-dl download art.json -o downloaded_imgs -r 1024x1024\r\n```\r\n---\r\n### Commands\r\n\r\n#### 1. Login\r\nLogin to Pinterest using your credentials to obtain browser cookies for scraping private boards and pins.\r\n\r\n**Syntax:**\r\n```bash\r\npinterest-dl login [options]\r\n```\r\n\r\n![login](/doc/images/pinterest-dl-login.gif)\r\n\r\n**Options:**\r\n- `-o`, `--output [file]`: File to save browser cookies for future use. (default: `cookies.json`)\r\n- `--client`: Choose the scraping client (`chrome` / `firefox`). (default: `chrome`)\r\n- `--headful`: Run in headful mode with browser window.\r\n- `--verbose`: Enable detailed output for debugging.\r\n- `--incognito`: Activate incognito mode for scraping.\r\n\r\n> [!TIP]\r\n> After entering `login` command, you will be prompted to enter your Pinterest email and password.\r\n> The tool will then save the browser cookies to the specified file for future use. (if not specified, it will save to `./cookies.json`)\r\n\r\n#### 2. Scrape\r\nExtract images from a specified Pinterest URL.\r\n\r\n**Syntax:**\r\n```bash\r\npinterest-dl scrape [url] [output_dir] [options]\r\n```\r\n\r\n![scrape](/doc/images/pinterest-dl-scrape.gif)\r\n\r\n**Options:**\r\n\r\n- `-c`, `--cookies [file]`: File containing browser cookies for private boards/pins. Run `login` command to obtain cookies.\r\n- `-l`, `--limit [number]`: Max number of image to download (default: 100).\r\n- `-r`, `--resolution [width]x[height]`: Minimum image resolution for download (e.g., 512x512).\r\n- `--timeout [second]`: Timeout in seconds for requests (default: 3).\r\n- `--json`: Save scraped URLs to a JSON file.\r\n- `--dry-run`: Execute scrape without downloading images.\r\n- `--verbose`: Enable detailed output for debugging.\r\n- `--client`: Choose the scraping client (`api` / `chrome` / `firefox`). (default: api)\r\n- `--incognito`: Activate incognito mode for scraping. (*chrome / firefox only*)\r\n- `--headful`: Run in headful mode with browser window. (*chrome / firefox only*)\r\n\r\n#### 3. Search\r\nSearch for images on Pinterest using a query. (*Experimental, currently only available in API mode*)\r\n\r\n**Syntax:**\r\n```bash\r\npinterest-dl search [query] [output_dir] [options]\r\n```\r\n\r\n![search](/doc/images/pinterest-dl-search.gif)\r\n\r\n**Options:**\r\n- `-c`, `--cookies [file]`: File containing browser cookies for private boards/pins. Run `login` command to obtain cookies.\r\n- `-l`, `--limit [number]`: Max number of image to download (default: 100).\r\n- `-r`, `--resolution [width]x[height]`: Minimum image resolution for download (e.g., 512x512).\r\n- `--timeout [second]`: Timeout in seconds for requests (default: 3).\r\n- `--json`: Save scraped URLs to a JSON file.\r\n- `--dry-run`: Execute scrape without downloading images.\r\n- `--verbose`: Enable detailed output for debugging.\r\n\r\n#### 4. Download\r\nDownload images from a list of URLs provided in a file.\r\n\r\n**Syntax:**\r\n```bash\r\npinterest-dl download [url_list] [options]\r\n```\r\n\r\n![download](/doc/images/pinterest-dl-download.gif)\r\n\r\n**Options:**\r\n- `-o`, `--output [directory]`: Output directory (default: ./<json_filename>).\r\n- `-r`, `--resolution [width]x[height]`: minimum resolution to download (e.g. 512x512).\r\n- `--verbose`: Enable verbose output.\r\n\r\n\r\n## \ud83d\udee0\ufe0f Python API\r\nYou can also use the `PinterestDL` class directly in your Python code to scrape and download images programmatically.\r\n\r\n### 1. Quick Scrape and Download\r\nThe following example shows how to scrape and download images from a Pinterest URL in one step.\r\n\r\n```python\r\nfrom pinterest_dl import PinterestDL\r\n\r\n# Initialize and run the Pinterest image downloader with specified settings\r\nimages = PinterestDL.with_api(\r\n    timeout=3,  # Timeout in seconds for each request (default: 3)\r\n    verbose=False,  # Enable detailed logging for debugging (default: False)\r\n).scrape_and_download(\r\n    url=\"https://www.pinterest.com/pin/1234567\",  # Pinterest URL to scrape\r\n    output_dir=\"images/art\",  # Directory to save downloaded images\r\n    limit=30,  # Max number of images to download \r\n    min_resolution=(512, 512),  # Minimum resolution for images (width, height) (default: None)\r\n    json_output=\"art.json\",  # File to save URLs of scraped images (default: None)\r\n    dry_run=False,  # If True, performs a scrape without downloading images (default: False)\r\n    add_captions=True,  # Adds image `alt` text as metadata to images (default: False)\r\n)\r\n```\r\n\r\n### 2. Scrape with Cookies for Private Boards\r\n**2a. Obtain cookies**\r\nYou need to first log in to Pinterest to obtain browser cookies for scraping private boards and pins.\r\n```python\r\nimport os\r\nimport json\r\n\r\nfrom pinterest_dl import PinterestDL\r\n\r\n# Make sure you don't expose your password in the code.\r\nemail = input(\"Enter Pinterest email: \")\r\npassword = os.getenv(\"PINTEREST_PASSWORD\")\r\n\r\n# Initialize browser and login to Pinterest\r\ncookies = PinterestDL.with_browser(\r\n    browser_type=\"chrome\",\r\n    headless=True,\r\n).login(email, password).get_cookies(\r\n    after_sec=7,  # Time to wait before capturing cookies. Login may take time.\r\n)\r\n\r\n# Save cookies to a file\r\nwith open(\"cookies.json\", \"w\") as f:\r\n    json.dump(cookies, f, indent=4)\r\n```\r\n\r\n**2b. Scrape with cookies**\r\nAfter obtaining cookies, you can use them to scrape private boards and pins.\r\n```python\r\nfrom pinterest_dl import PinterestDL\r\n\r\n# Load cookies from a file\r\nwith open(\"cookies.json\", \"r\") as f:\r\n    cookies = json.load(f)\r\n\r\n# Initialize and run the Pinterest image downloader with specified settings\r\nimages = (\r\n    PinterestDL.with_api()\r\n    .with_cookies(\r\n        cookies,  # cookies in selenium format\r\n    )\r\n    .scrape_and_download(\r\n        url=\"https://www.pinterest.com/pin/1234567\",  # Assume this is a private board URL\r\n        output_dir=\"images/art\",  # Directory to save downloaded images\r\n        limit=30,  # Max number of images to download\r\n    )\r\n)\r\n```\r\n\r\n### 3. Detailed Scraping with Lower-Level Control\r\n\r\nUse this example if you need more granular control over scraping and downloading images.\r\n\r\n#### 3a. With API\r\n```python\r\nimport json\r\n\r\nfrom pinterest_dl import PinterestDL\r\n\r\n# 1. Initialize PinterestDL with API.\r\nscraped_images = PinterestDL.with_api().scrape(\r\n    url=\"https://www.pinterest.com/pin/1234567\",  # URL of the Pinterest page\r\n    limit=30,  # Maximum number of images to scrape\r\n    min_resolution=(512, 512),  # <- Only available to set in the API. Browser mode will have to pruned after download.\r\n)\r\n\r\n# 2. Save Scraped Data to JSON\r\n# Convert scraped data into a dictionary and save it to a JSON file for future access\r\nimages_data = [img.to_dict() for img in scraped_images]\r\nwith open(\"art.json\", \"w\") as f:\r\n    json.dump(images_data, f, indent=4)\r\n\r\n# 3. Download Images\r\n# Download images to a specified directory\r\ndownloaded_imgs = PinterestDL.download_images(images=scraped_images, output_dir=\"images/art\")\r\n\r\nvalid_indices = list(range(len(downloaded_imgs)))  # All images are valid to add captions\r\n\r\n# 4. Add Alt Text as Metadata\r\n# Extract `alt` text from images and set it as metadata in the downloaded files\r\nPinterestDL.add_captions(images=downloaded_imgs, indices=valid_indices)\r\n```\r\n\r\n#### 3b. With Browser\r\n```python\r\nimport json\r\n\r\nfrom pinterest_dl import PinterestDL\r\n\r\n# 1. Initialize PinterestDL with API.\r\nscraped_images = PinterestDL.with_browser(\r\n    browser_type=\"chrome\",  # Browser type to use ('chrome' or 'firefox')\r\n    headless=True,  # Run browser in headless mode\r\n).scrape(\r\n    url=\"https://www.pinterest.com/pin/1234567\",  # URL of the Pinterest page\r\n    limit=30,  # Maximum number of images to scrape\r\n)\r\n\r\n# 2. Save Scraped Data to JSON\r\n# Convert scraped data into a dictionary and save it to a JSON file for future access\r\nimages_data = [img.to_dict() for img in scraped_images]\r\nwith open(\"art.json\", \"w\") as f:\r\n    json.dump(images_data, f, indent=4)\r\n\r\n# 3. Download Images\r\n# Download images to a specified directory\r\ndownloaded_imgs = PinterestDL.download_images(images=scraped_images, output_dir=\"images/art\")\r\n\r\n# 4. Prune Images by Resolution\r\n# Remove images that do not meet the minimum resolution criteria\r\nvalid_indices = PinterestDL.prune_images(images=downloaded_imgs, min_resolution=(200, 200))\r\n\r\n# 5. Add Alt Text as Metadata\r\n# Extract `alt` text from images and set it as metadata in the downloaded files\r\nPinterestDL.add_captions(images=downloaded_imgs, indices=valid_indices)\r\n```\r\n\r\n## \ud83d\udcdc License\r\n[Apache License 2.0](LICENSE)\r\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "An unofficial Pinterest image downloader",
    "version": "0.3.2",
    "project_urls": {
        "Homepage": "https://github.com/sean1832/pinterest-dl",
        "Issues": "https://github.com/sean1832/pinterest-dl/issues"
    },
    "split_keywords": [
        "pinterest",
        " image downloader",
        " selenium",
        " web scraping"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "30048062895e2ba84f6a496175f3f490b9375466c7a2a273ee13a452bbba74ea",
                "md5": "d4898e691cd79dec6964adb52545bb1c",
                "sha256": "2711783f7890011b432f2837c9f4c1d9431a0fe9f0620e055c454151e255a68f"
            },
            "downloads": -1,
            "filename": "pinterest_dl-0.3.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d4898e691cd79dec6964adb52545bb1c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 35635,
            "upload_time": "2024-12-14T04:52:04",
            "upload_time_iso_8601": "2024-12-14T04:52:04.108405Z",
            "url": "https://files.pythonhosted.org/packages/30/04/8062895e2ba84f6a496175f3f490b9375466c7a2a273ee13a452bbba74ea/pinterest_dl-0.3.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "61f1af423b9e31a2a8adc4295288294b2828bb0b7d4b0ee29d87db8c08b08fa9",
                "md5": "ecb3dfdc4b345fd4bf037f850a829c80",
                "sha256": "df597a3502e905ef13b3e244fe488def0cfd0667a6a4ac6e4e138f93d51915e4"
            },
            "downloads": -1,
            "filename": "pinterest_dl-0.3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "ecb3dfdc4b345fd4bf037f850a829c80",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 199190,
            "upload_time": "2024-12-14T04:52:06",
            "upload_time_iso_8601": "2024-12-14T04:52:06.262493Z",
            "url": "https://files.pythonhosted.org/packages/61/f1/af423b9e31a2a8adc4295288294b2828bb0b7d4b0ee29d87db8c08b08fa9/pinterest_dl-0.3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-14 04:52:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sean1832",
    "github_project": "pinterest-dl",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pinterest-dl"
}
        
Elapsed time: 0.79925s