Created
October 28, 2017 19:01
-
-
Save Chalarangelo/ec5c8bed17396e8e55cf3305dbb88f56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import time | |
from selenium import webdriver | |
from PIL import Image | |
from io import BytesIO | |
url = "https://unsplash.com" | |
driver = webdriver.Firefox(executable_path=r'geckodriver.exe') | |
driver.get(url) | |
driver.execute_script("window.scrollTo(0,1000);") | |
time.sleep(5) | |
image_elements = driver.find_elements_by_css_selector("#gridMulti img") | |
i = 0 | |
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)) | |
image.save("./images/image" + str(i) + "." + image.format, image.format) | |
i += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment