Uncategorized

How to Download and Image from a website using Selenium, Python, Requests, and Shutil

#please like and subscribe!!!!

import time
import requests
import shutil
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service

#set location the location of the webdriver
s = Service('/usr/local/bin/chromedriver')

driver = webdriver.Chrome(service=s)
driver.get("https://corbah.com/")
time.sleep(3)

img = driver.find_element(by=By.XPATH, value="/html/body/main/div[5]/div/ul/li[2]/div[1]/a/img")
src = img.get_attribute('src')
url = src

response = requests.get(url, stream=True)
with open('img.png', 'wb') as out_file:
    shutil.copyfileobj(response.raw, out_file)
del response