Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Uses Selenium to delete every topic in a Google Group (rate of around 2k/hour deletions)
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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.