Created
October 13, 2019 16:47
-
-
Save TioBorracho/213a0d58c48d2a2f2ddf5f13b5a5a043 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
import time | |
import pickle | |
# Setup the browser. Could be headless, just testing. | |
options = webdriver.ChromeOptions() | |
options.add_argument('--ignore-certificate-errors') | |
options.add_argument("--test-type") | |
options.binary_location = "/usr/bin/chromium" | |
driver = webdriver.Chrome(chrome_options=options) | |
# Get the initial page | |
driver.get('https://photos.google.com') | |
# Open already generated cookies to avoid loging in | |
cookies = pickle.load(open("cookies.pkl", "rb")) | |
for cookie in cookies: | |
driver.add_cookie(cookie) | |
# Search for a specific file by name | |
driver.get('https://photos.google.com/search/IMG_20191008_183025') | |
# This is too hacky, there must be a better way to tell apart the image elements. | |
elems = driver.find_elements_by_xpath('//a[@tabindex=0][@aria-label]') | |
# Also too hacky, if there is only one result, it is the last element with this selector. | |
elems[len(elems)-1].click() | |
elem = driver.switch_to.active_element | |
elem.send_keys(Keys.SHIFT, 'd') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment