import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from PIL import Image
import os
all_urls = [{'url':'url1', 'name':'pic1'},
{'url':'url2', 'name':'pic2'},
{'url':'url3', 'name':'pic3'},]
def login():
driver = webdriver.Chrome(executable_path='C:/Program Files/ntko plugin/chromedriver')
driver.set_window_size(1920, 1080)
print('initializing')
return driver
def get_screen(driver, urls):
count = 1
for url in urls:
print(url)
driver.get(url["url"])
print('screen shotting -> %s'% url)
count += 1
time.sleep(2)
driver.get_screenshot_as_file("./screen_shot/{}.png".format(url["name"]))
print("{}.png saved".format(url["name"]))
def crop_img():
for img in os.listdir('./screen_shot'):
if img.endswith('.png'):
print('%s cutting'% img)
im = Image.open('./screen_shot/%s'% img)
x = 320
y = 162
w = 920
h = 720
region = im.crop((x, y, x+w, y+h))
region.save("./screenshot_final/%s" % img)
if __name__ == '__main__':
driver = login()
get_screen(driver, all_urls)
driver.quit()
crop_img()
ps: