Created
August 7, 2017 05:16
-
-
Save dado3212/d65ae292404e35546681fdfa067c42dd to your computer and use it in GitHub Desktop.
Uses Selenium to delete every topic in a Google Group (rate of around 2k/hour deletions)
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
import time | |
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
import selenium.webdriver.support.ui as ui | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.support import expected_conditions as EC | |
credentials = { | |
# login credentials for google group | |
'username': '<username>', | |
'password': '<password>', | |
# name of the group | |
'group_name': '<group_name>', | |
} | |
def delete_everything(driver): | |
# Open the main window | |
wait = ui.WebDriverWait(driver, 10) | |
driver.get('https://accounts.google.com/AccountChooser?continue=https%3A%2F%2Fgroups.google.com%2Fd%2Fforum%2F' + credentials['group_name'] + '&hl=en&service=groups2') | |
# Login | |
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'input[type="email"]'))) | |
username = driver.find_element_by_css_selector('input[type="email"]') | |
username.send_keys(credentials['username']) | |
username.send_keys(Keys.ENTER) | |
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'input[type="password"]'))) | |
password = driver.find_element_by_css_selector('input[type="password"]') | |
password.send_keys(credentials['password']) | |
password.send_keys(Keys.ENTER) | |
# ============= | |
# DELETION | |
# ============= | |
deleted = True | |
while (deleted): | |
deleted = False | |
# Choose a topic | |
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'div[role="listitem"]'))) | |
topic = driver.find_element_by_css_selector('div[role="listitem"]') | |
if topic: | |
topic.click() | |
# Open actions | |
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'div[data-title="Actions"]'))) | |
actions_button = driver.find_element_by_css_selector('div[data-title="Actions"]') | |
actions_button.click() | |
# Choose delete | |
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, '#ma_DELETE_TOPICS'))) | |
delete_option = driver.find_element_by_css_selector('#ma_DELETE_TOPICS') | |
delete_option.click() | |
# Choose 'Other' option | |
wait.until(EC.element_to_be_clickable((By.XPATH, "//label[contains(text(), 'Other')]"))) | |
other_option = driver.find_element_by_xpath("//label[contains(text(), 'Other')]") | |
other_option_parent = other_option.find_element_by_xpath("..") | |
radio = other_option_parent.find_element_by_css_selector('span[role="radio"]') | |
radio.click() | |
# Submit delete request | |
driver.find_element_by_css_selector('#dialog_ok').click() | |
deleted = True | |
finished = False | |
while not finished: | |
driver = webdriver.Chrome('./chromedriver') # Download from https://goo.gl/aQWcRe | |
try: | |
delete_everything(driver) | |
finished = True | |
except Exception as e: | |
print e | |
finished = False | |
driver.quit() | |
time.sleep(5) # Wait 5 seconds, and go again |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment