Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from selenium import webdriver
- from selenium.webdriver import Keys
- from selenium.webdriver.common.by import By
- from selenium.webdriver.support.ui import WebDriverWait
- from selenium.webdriver.support import expected_conditions as ec
- from selenium.common.exceptions import TimeoutException
- import time
- driver = webdriver.Firefox()
- driver.get('https://accounts.snapchat.com/accounts/v2/login')
- driver.maximize_window()
- my_username = ""
- my_password = ""
- wait = WebDriverWait(driver, 10)
- # handle cookie pop up
- try:
- cookie = wait.until(ec.visibility_of_element_located(
- (By.XPATH, '/html/body/div[2]/div/div/div[4]/div/section/div/section/div[2]/div/div/div/div[3]/button[1]')))
- cookie.click()
- except TimeoutException:
- print("no cookie popup")
- # login
- time.sleep(1)
- enter_username = driver.find_element(By.XPATH, '//*[@id="accountIdentifier"]')
- enter_username.send_keys(my_username, Keys.RETURN)
- time.sleep(2)
- enter_password = driver.find_element(By.XPATH, '//*[@id="password"]')
- enter_password.send_keys(my_password, Keys.RETURN)
- # navigate to "my data"
- my_data = wait.until(ec.visibility_of_element_located(
- (By.XPATH, '/html/body/div/div[1]/main/div[3]/div[3]/div[1]/a[1]')))
- my_data.click()
- # select download data
- select_data_xpath = {
- 'html': '/html/body/div[4]/div/main/div[2]/div/div[2]/div/div[2]/section[1]/div[3]/div/div[3]/div/div/button',
- 'json': '/html/body/div[4]/div/main/div[2]/div/div[2]/div/div[2]/section[1]/div[4]/div/div[3]/div/div/button',
- 'user': '/html/body/div[4]/div/main/div[2]/div/div[2]/div/div[2]/section[1]/div[5]/div/div[3]/label',
- 'chat': '/html/body/div[4]/div/main/div[2]/div/div[2]/div/div[3]/section[1]/div[6]/div/div[3]/label',
- 'spotlight': '/html/body/div[4]/div/main/div[2]/div/div[2]/div/div[3]/section[1]/div[7]/div/div[3]/label',
- 'shopping': '/html/body/div[4]/div/main/div[2]/div/div[2]/div/div[3]/section[1]/div[8]/div/div[3]/label',
- 'support': '/html/body/div[4]/div/main/div[2]/div/div[2]/div/div[3]/section[1]/div[9]/div/div[3]/label',
- 'ranking': '/html/body/div[4]/div/main/div[2]/div/div[2]/div/div[3]/section[1]/div[10]/div/div[3]/label',
- 'other': '/html/body/div[4]/div/main/div[2]/div/div[2]/div/div[3]/section[1]/div[12]/div/div[3]/label'
- }
- def click_data_buttons(dictionary):
- for value in dictionary.values():
- data_button = driver.find_element(By.XPATH, value)
- data_button.click()
- click_data_buttons(select_data_xpath)
Advertisement
Add Comment
Please, Sign In to add comment