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()