Created
July 15, 2014 12:46
-
-
Save Saren-Arterius/da96e71042a0b6ed8b35 to your computer and use it in GitHub Desktop.
hkgolden-lm-deleter
This file contains hidden or 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/python | |
from selenium.common.exceptions import NoSuchElementException | |
from selenium import webdriver | |
from time import time | |
class HKGoldenLMDeleter(object): | |
hkg_url = "http://forum10.hkgolden.com/login.aspx?error=1" | |
def __init__(self, email, password): | |
self.email = email | |
self.password = password | |
self.__login() | |
def __login(self): | |
self.browser = webdriver.Firefox() | |
self.browser.get(self.hkg_url) | |
while True: | |
self.browser.find_element_by_xpath("//input[@id='ctl00_ContentPlaceHolder1_txt_email']").clear() | |
self.browser.find_element_by_xpath("//input[@id='ctl00_ContentPlaceHolder1_txt_email']").send_keys(self.email) | |
self.browser.find_element_by_xpath("//input[@id='ctl00_ContentPlaceHolder1_txt_pass']").clear() | |
self.browser.find_element_by_xpath("//input[@id='ctl00_ContentPlaceHolder1_txt_pass']").send_keys(self.password) | |
file_name = "{0}.png".format(time()) | |
self.browser.save_screenshot(file_name) | |
captcha = input("Please enter the captcha as seen at {0}: ".format(file_name)) | |
self.browser.find_element_by_xpath("//input[@id='ctl00_ContentPlaceHolder1_txtChkCode']").clear() | |
self.browser.find_element_by_xpath("//input[@id='ctl00_ContentPlaceHolder1_txtChkCode']").send_keys(captcha) | |
self.browser.find_element_by_xpath("//input[@id='ctl00_ContentPlaceHolder1_linkb_login']").click() | |
if "login.aspx" in self.browser.current_url: | |
print("Login error!") | |
else: | |
break | |
def delete_all_lms(self): | |
self.browser.find_element_by_xpath("//span[@id='ctl00_ContentPlaceHolder1_lb_UserName']/a").click() | |
while True: | |
try: | |
self.browser.find_element_by_xpath("//input[@src='img/close_button.png']") | |
except NoSuchElementException: | |
break | |
for elem in self.browser.find_elements_by_xpath("//input[@type='checkbox']"): | |
try: | |
if "selectBookmark" in elem.get_attribute("name"): | |
elem.click() | |
except: | |
pass | |
self.browser.find_element_by_xpath("//input[@id='ctl00_ContentPlaceHolder1_mainTab_mainTab4_deleteBookmark']").click() | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment