Skip to content

Instantly share code, notes, and snippets.

@gkiryaziev
Last active September 21, 2022 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gkiryaziev/e7f33ed2571250f83aed5cc14b9a0f99 to your computer and use it in GitHub Desktop.
Save gkiryaziev/e7f33ed2571250f83aed5cc14b9a0f99 to your computer and use it in GitHub Desktop.
Colorize image with https://imagecolorizer.com/ site and selenium.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import requests
import time
image_file = "ScanImage003.jpg"
color_file = "ScanImage003-Colorized.jpg"
options = webdriver.ChromeOptions()
# options.add_argument("headless");
# options.add_argument("disable-gpu");
options.add_argument("disable-infobars");
options.add_argument("disable-dev-sh-usage");
options.add_argument("no-sandbox");
options.add_argument("window-size=1024,768");
options.add_argument("lang=en");
driver = webdriver.Chrome(options=options)
driver.implicitly_wait(10)
driver.get(r"https://imagecolorizer.com/colorize.html")
time.sleep(10)
driver.find_element(By.ID, "file").send_keys(r'C:/' + image_file)
WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, r'//*[@id="upload_table"]/tbody/tr/td[5]/button[2]'))
).click()
href_link = WebDriverWait(driver, 40).until(
EC.visibility_of_element_located((By.XPATH, r'//*[@id="upload_table"]/tbody/tr/td[5]/a[1]'))
).get_attribute("href")
resp = requests.get(href_link)
with open(color_file, "wb") as f:
f.write(resp.content)
driver.close()
print("Done.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment