Skip to content

Instantly share code, notes, and snippets.

@gainskills
Forked from Chalarangelo/unscrape.py
Last active January 26, 2018 06:05
Show Gist options
  • Save gainskills/6d5b1ad35a2f60529a422074a455a8da to your computer and use it in GitHub Desktop.
Save gainskills/6d5b1ad35a2f60529a422074a455a8da to your computer and use it in GitHub Desktop.
import requests
import time
import os
from selenium import webdriver
from PIL import Image
from io import BytesIO
url = "https://unsplash.com"
driver = webdriver.Firefox(executable_path=r'geckodriver')
driver.get(url)
driver.execute_script("window.scrollTo(0,1000);")
time.sleep(5)
image_elements = driver.find_elements_by_css_selector("#gridMulti img")
for image_element in image_elements:
image_url = image_element.get_attribute("src")
# Send an HTTP GET request, get and save the image from the response
image_object = requests.get(image_url)
image = Image.open(BytesIO(image_object.content))
if not os.path.exists("./images"):
os.mkdir("./images")
image.save("./images/image" + str(i) + "." + image.format, image.format)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment