Last active
January 11, 2016 17:55
-
-
Save awesomebytes/7dcc241eecc322bb7dcd 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
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
Created on 01/11/15 | |
@author: sampfeiffer | |
delete_spammer_comments.py | |
You need selenium: | |
pip install selenium | |
And Firefox | |
""" | |
from selenium import webdriver | |
from selenium.common.exceptions import TimeoutException, NoSuchElementException | |
HEADER = '\033[95m' | |
OKBLUE = '\033[94m' | |
OKGREEN = '\033[92m' | |
WARNING = '\033[93m' | |
FAIL = '\033[91m' | |
ENDC = '\033[0m' | |
def login(web_driver, login_url): | |
driver.get(login_url) | |
raw_input("Login manually, when you are done, press any key + Enter") | |
def hit_delete(web_driver, url): | |
print "Hitting delete writing reason: spam at url:\n " + str(url) | |
driver.get(url) | |
try: | |
comment_field = driver.find_element_by_id("comment") | |
comment_field.send_keys('spam') | |
driver.find_element_by_name("delete").click() | |
except NoSuchElementException: | |
print FAIL + "Could not find element, probably the page was already deleted" + ENDC | |
if __name__ == '__main__': | |
login_url = "http://wiki.ros.org/action/login/Documentation?action=login" | |
# Fill here urls to delete... | |
urls_to_delete = ['http://wiki.ros.org/Call%20%40%201800~298~2042%20QUICKBOOKS%20Technical%20Support%20Team%20Phone%20Number'] | |
driver = webdriver.Firefox() | |
login(driver, login_url) | |
for url in urls_to_delete: | |
delete_url = url + "?action=DeletePage" | |
hit_delete(driver, delete_url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment