### Implement Pinterest Search and Download Workflow Source: https://context7.com/iamatulsingh/pinscrape/llms.txt A complete example showing the recommended workflow using the Pinterest client, including initialization, searching for multiple terms, and parallel downloading of images. ```python from pinscrape import Pinterest pinterest = Pinterest(sleep_time=1.5) search_terms = ["abstract art", "modern architecture"] for term in search_terms: urls = pinterest.search(term, page_size=10) pinterest.download( url_list=urls, number_of_workers=3, output_folder=f"images/{term}" ) ``` -------------------------------- ### Install Pinscrape Package Source: https://github.com/iamatulsingh/pinscrape/blob/main/README.md This command installs the pinscrape package using pip. It is a prerequisite for using the package's functionalities. ```bash pip install pinscrape ``` -------------------------------- ### Get Board Details using Pinterest.get_pin_details() Source: https://context7.com/iamatulsingh/pinscrape/llms.txt Retrieves metadata for a Pinterest board, such as its creation date. Requires the username of the board owner and the board's slug (URL-friendly name). Handles cases where the board might not be found or is private. ```python from pinscrape import Pinterest p = Pinterest() # Get board details by username and board slug # The board slug is the URL-friendly board name created_at = p.get_pin_details( username="canva", board="design-trends" ) print(f"Board created at: {created_at}") # Output: Board created at: 2015-03-12T18:45:23 # Example: Check multiple boards boards_to_check = [ ("pinterest", "diy-crafts"), ("etsy", "home-decor"), ("canva", "marketing-ideas") ] for username, board in boards_to_check: created = p.get_pin_details(username=username, board=board) if created: print(f"@{username}/{board}: Created {created}") else: print(f"@{username}/{board}: Not found or private") ``` -------------------------------- ### Legacy Scraper Interface (Deprecated) Source: https://context7.com/iamatulsingh/pinscrape/llms.txt Configuration example for the legacy `scraper` interface, which uses search engines as an intermediary to find Pinterest URLs. This interface is deprecated in favor of the `Pinterest` class but is maintained for backward compatibility. ```python from pinscrape import scraper # Configure scraping parameters keyword = "sunset photography" output_folder = "sunset_images" proxies = {} # Optional proxy configuration number_of_workers = 10 max_images = 5 ``` -------------------------------- ### Initialize Pinterest Class Source: https://context7.com/iamatulsingh/pinscrape/llms.txt Demonstrates how to initialize the `Pinterest` class, the primary interface for interacting with Pinterest. Shows basic initialization and configuration with custom user agents, proxies, and request delay times. ```python from pinscrape import Pinterest # Basic initialization p = Pinterest() # Full configuration with all options p = Pinterest( user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36", proxies={ "http": "http://proxy.example.com:8080", "https": "https://proxy.example.com:8080" }, sleep_time=2.0 # Delay between requests in seconds ) # Access error logs if needed print(p.errors) # List of any errors encountered during operations ``` -------------------------------- ### Scrape Images using Pinterest API with Pinscrape Source: https://github.com/iamatulsingh/pinscrape/blob/main/README.md Demonstrates how to use the pinscrape package to download images from Pinterest. It initializes the Pinterest scraper with optional proxies and sleep time, searches for images based on a keyword, and then downloads them to a specified output folder. It also shows how to retrieve details of a specific Pinterest board. ```python from pinscrape import scraper, Pinterest keyword = "messi" output_folder = "output" proxies = {} number_of_workers = 10 images_to_download = 1 def using_search_engine(): # This is deprecated now details = scraper.scrape(keyword, output_folder, proxies, number_of_workers, images_to_download, sleep_time=2) if details["isDownloaded"]: print("\nDownloading completed !!") print(f"\nTotal urls found: {len(details['extracted_urls'])}") print(f"\nTotal images downloaded (including duplicate images): {len(details['urls_list'])}") print(details) else: print("\nNothing to download !!", details) def using_pinterest_apis(): p = Pinterest(proxies=proxies, sleep_time=2) # you can also pass `user_agent` here. images_url = p.search(keyword, images_to_download) p.download(url_list=images_url, number_of_workers=number_of_workers, output_folder=output_folder) board_details = p.get_pin_details(username='canva', board='design-trends') # you can now check any board details of a user. print(board_details) print(board_details.get('resource_response', {}).get('data', {}).get('created_at')) ``` -------------------------------- ### Download Images using Pinterest.download() Source: https://context7.com/iamatulsingh/pinscrape/llms.txt Downloads a list of image URLs to a specified local folder. This method utilizes multi-threading for concurrent downloads and includes automatic deduplication of images using perceptual hashing. The `output_folder` is created if it does not exist. ```python from pinscrape import Pinterest p = Pinterest(sleep_time=0.5) # Search for images image_urls = p.search("minimalist art", page_size=20) # Download images to a folder # number_of_workers: concurrent download threads # output_folder: destination directory (created if doesn't exist) p.download( url_list=image_urls, number_of_workers=5, output_folder="downloads/minimalist_art" ) # Complete workflow: search and download def download_pinterest_images(keyword, count=10, output_dir="output"): pinterest = Pinterest(sleep_time=1) urls = pinterest.search(keyword, page_size=count) print(f"Found {len(urls)} images for '{keyword}'") if urls: pinterest.download( url_list=urls, number_of_workers=3, output_folder=f"{output_dir}/{keyword.replace(' ', '_')}" ) print(f"Downloaded to {output_dir}/{keyword.replace(' ', '_')}") return urls # Usage download_pinterest_images("vintage cars", count=15, output_dir="my_images") ``` -------------------------------- ### Scrape Pinterest Images with Legacy Interface Source: https://context7.com/iamatulsingh/pinscrape/llms.txt Demonstrates how to use the legacy scraper interface to download images based on a keyword. It returns a dictionary containing download status, URLs found, and any errors encountered. ```python details = scraper.scrape( key=keyword, output_folder=output_folder, proxies=proxies, threads=number_of_workers, max_images=max_images, sleep_time=2 ) if details["isDownloaded"]: print(f"URLs found: {len(details['extracted_urls'])}") else: print(f"Errors: {details['error_stack']}") ``` -------------------------------- ### Search for Images using Pinterest.search() Source: https://context7.com/iamatulsingh/pinscrape/llms.txt Searches Pinterest for images based on a keyword query. The `search` method returns a list of direct URLs to original resolution images. The `page_size` parameter controls the number of results returned. ```python from pinscrape import Pinterest p = Pinterest(sleep_time=1) # Search for images with a keyword # page_size controls how many results to return (default: 26) image_urls = p.search("nature wallpaper", page_size=10) # Results are direct URLs to original resolution images print(f"Found {len(image_urls)} images") for url in image_urls[:3]: print(url) # Output example: # https://i.pinimg.com/originals/ab/cd/ef/abcdef123456.jpg # Search with different queries landscape_urls = p.search("mountain landscape", page_size=50) portrait_urls = p.search("portrait photography", page_size=25) ``` -------------------------------- ### Pinterest Search and Download Source: https://github.com/iamatulsingh/pinscrape/blob/main/README.md Methods to search for images based on keywords and download them to a local directory. ```APIDOC ## POST /pinterest/search ### Description Searches Pinterest for images based on a provided keyword and returns a list of image URLs. ### Method POST ### Parameters #### Request Body - **keyword** (string) - Required - The search term to query on Pinterest. - **images_to_download** (integer) - Required - The number of images to retrieve. ### Response #### Success Response (200) - **urls** (array) - A list of image source URLs. --- ## POST /pinterest/download ### Description Downloads a list of image URLs to a specified local directory using multi-threading. ### Method POST ### Parameters #### Request Body - **url_list** (array) - Required - List of image URLs to download. - **output_folder** (string) - Required - Local path to save images. - **number_of_workers** (integer) - Optional - Number of concurrent threads for downloading. ``` -------------------------------- ### Utilize Image Processing and Utility Functions Source: https://context7.com/iamatulsingh/pinscrape/llms.txt Covers helper functions for image deduplication using perceptual hashing, directory management, and timestamp generation for API requests. ```python from pinscrape.utils import image_hash, ensure_dir, current_epoch_ms import cv2 image = cv2.imread("photo.jpg") hash_value = image_hash(image, hash_size=8) output_path = ensure_dir("downloads/batch1") timestamp = current_epoch_ms() ``` -------------------------------- ### Pinterest Board Details Source: https://github.com/iamatulsingh/pinscrape/blob/main/README.md Retrieve metadata and details for specific user boards on Pinterest. ```APIDOC ## GET /pinterest/board ### Description Fetches detailed information about a specific Pinterest board owned by a user. ### Method GET ### Parameters #### Query Parameters - **username** (string) - Required - The Pinterest username. - **board** (string) - Required - The slug of the board to retrieve. ### Response #### Success Response (200) - **resource_response** (object) - The raw JSON response containing board metadata, creation date, and pin details. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.