Download Images from Pinterest Board
This script helps you to download images from Pinterest Boards to your computer. Currently it saves only 16 images from the board and am looking for a way to fetch all the images. You can copy the following script to your text editor and save it with “.py” extention eg: pinboardSave.py
Python 3 code for downloading images from pinterest board.
Requirements:
- Python3
- Tkinter
- Lxml
- Requests
- bs4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
URL_String=input("Please enter your Pinterest board url {https://www.pinterest.com/username/board-slug}: ") from tkinter import filedialog FOLDER_URL=filedialog.askdirectory(title="Select the folder where you want to save the images: ") if FOLDER_URL=='': print('Folder not selected') exit(0) from lxml import html import requests page=requests.get(URL_String) print(page.status_code) tree=html.fromstring(page.content) print(tree) pins=tree.xpath('//div[@class="GrowthUnauthPinImage"]//@href') import requests, bs4 import urllib print("Pin from board " + URL_String + " will be saved on " + FOLDER_URL) print("Array of pins in board") print(pins) print("Total number of pins " + str(len(pins))) img_count=1 for pin in pins: print("Saving Image Number: " + str(n)) page=requests.get('http://www.pinterest.com'+pin) print("Pin " + pin + " processed") page_soup=bs4.BeautifulSoup(page.text,"lxml") page_element=page_soup.select('img[src]') image_address=page_element[0].attrs['src'] image_title=page_element[0].attrs['alt'] if len(image_title) < 2: image_title=str(n) resource=urllib.request.urlopen(image_address) output=open(FOLDER_URL+"/"+"Image-"+image_title[:50]+".jpg","wb") output.write(resource.read()) output.close() img_count=img_count+1 |
Python 2 code for downloading images from pinterest board.
Requirements:
- Python2
- Tkinter
- Lxml
- Requests
- bs4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
URL_String=raw_input("Please enter your Pinterest board url {https://www.pinterest.com/username/board-slug}: ") from Tkinter import * import tkFileDialog as filedialog FOLDER_URL=filedialog.askdirectory(title="Select the folder where you want to save the images: ") if FOLDER_URL=='': print('Folder not selected') exit(0) from lxml import html import requests page=requests.get(URL_String) print(page.status_code) tree=html.fromstring(page.content) print(tree) pins=tree.xpath('.//div[@class="GrowthUnauthPinImage"]/a/@href') import requests, bs4 import urllib print("Pin from board " + URL_String + " will be saved on " + FOLDER_URL) print("Array of pins in board") print(pins) print("Total number of pins " + str(len(pins))) img_count=1 for pin in pins: print("Saving Image Number: " + str(n)) page=requests.get('http://www.pinterest.com'+pin) print("Pin " + pin + " processed") page_soup=bs4.BeautifulSoup(page.text,"lxml") page_element=page_soup.select('img[src]') image_address=page_element[0].attrs['src'] image_title=page_element[0].attrs['alt'] if len(image_title) < 2: image_title=str(n) resource=urllib.urlopen(image_address) output=open(FOLDER_URL+"/"+"Image-"+image_title[:50]+".jpg","wb") output.write(resource.read()) output.close() img_count=img_count+1 |