From c5d227edd2f1a3383a3e0fea02fd16864dcff07d Mon Sep 17 00:00:00 2001 From: Dylan Caponi Date: Sat, 8 Oct 2022 23:21:27 -0500 Subject: [PATCH] Add selenium python snippet --- snippets/main.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 snippets/main.py diff --git a/snippets/main.py b/snippets/main.py new file mode 100644 index 0000000..3c4254e --- /dev/null +++ b/snippets/main.py @@ -0,0 +1,39 @@ +from selenium import webdriver +from selenium.webdriver.chrome.service import Service +from selenium.webdriver.chrome.options import Options + +URL = 'http://www.google.com' +TMP_IMG = 'screenshot.png' + +s=Service('./chromedriver105') +chrome_options = Options() +chrome_options.add_argument("--headless") +browser = webdriver.Chrome(service=s, options=chrome_options) + +browser.get(URL) + +# Take screenshot +screenshot = browser.save_screenshot(TMP_IMG) +print(screenshot) + +# Get current time truncate to minute +import datetime +now = datetime.datetime.now() +now = now.replace(second=0, microsecond=0) +print(now) + +# Load screenshot +from PIL import Image +im = Image.open(TMP_IMG) + +# Make hash of screenshot image + URL + time +import hashlib +hash = hashlib.sha256() +hash.update(im.tobytes()) +hash.update(browser.current_url.encode('utf-8')) +hash.update(now.isoformat().encode('utf-8')) +print(hash) +hash = hash.hexdigest() +print(hash) + +browser.quit()