def chooseNickname(self, url): nickname = 'mc' + misc.random_alphaNumeric_string(6, 3) + 'n' self.navigate(url) if self.waitElement( EC.element_to_be_clickable( (By.XPATH, '//div[@class="ak-game-download"]/a')), 10): print('Email confirmed') else: misc.ePrint('invalid confirmation email') return None if not self.navigate('https://www.dofus.com/fr/'): return None time.sleep(3) # self.executeScript(EC.element_to_be_clickable((By.XPATH, '//a[@class="ak-close"]')), 10) # close cookies self.executeScript( EC.element_to_be_clickable( (By.XPATH, '//a[@class="login ak-modal-trigger"]')), 10) # open nickname ui time.sleep(1) self.waitElement( EC.visibility_of_element_located((By.ID, 'usernickname')), 10).send_keys(nickname) # write nickname time.sleep(1) self.waitElement( EC.element_to_be_clickable( (By.XPATH, '//input[@class="btn btn-primary ak-btn-big"]')), 10).click() # click confirm btn time.sleep(1) print('Nickname set: ' + nickname) return nickname
def navigate(self, url, proxy = None): try: self.driver.get(url) except Exception as e: print(e, end='') misc.ePrint('failed to navigate to \'' + url + '\'') return False else: return True
def waitElement(self, element, timeout): wait = WebDriverWait(self.driver, timeout) try: element = wait.until(element) except Exception as e: print(e, end='') misc.ePrint('timeout exception') return None else: return element
def startFirefoxBrowser(self, strategy, headless, proxy = None): try: opt = webdriver.FirefoxOptions() opt.headless = headless firefox_capabilities = self.handleFirefoxCapabilities(strategy, proxy) if platform.architecture()[0] == '32bit': bin_path = './geckodriver-linux32' else: bin_path = './geckodriver-linux64' self.driver = webdriver.Firefox(executable_path=bin_path, capabilities=firefox_capabilities, firefox_options=opt) except Exception as e: print(e, end='') misc.ePrint('failed to launch Firefox Browser') sys.exit(1)
def getOnlineProxy(): url = 'http://pubproxy.com/api/proxy' response = requests.get(url) try: currentProxy = json.loads(response.text)['data'][0]['ipPort'] except: print(response.text) misc.ePrint('API may be dead ?') exit(1) print('Trying with ' + currentProxy) if is_bad_proxy(currentProxy): return None else: return currentProxy
def register(self, mail): login = '******' + misc.random_alphaNumeric_string(6, 3) + 'l' password = '******' + misc.random_alphaNumeric_string(6, 3) + 'p' if self.waitElement(EC.element_to_be_clickable( (By.ID, "ak_field_4")), 15) is None: misc.ePrint('cannot find registration form') return None self.waitElement( EC.visibility_of_element_located((By.ID, "userlogin")), 1).send_keys(login) self.waitElement( EC.visibility_of_element_located((By.ID, "user_password")), 1).send_keys(password) self.waitElement( EC.visibility_of_element_located((By.ID, "user_password_confirm")), 1).send_keys(password) self.waitElement( EC.visibility_of_element_located((By.ID, "user_mail")), 1).send_keys(mail) Select( self.waitElement( EC.visibility_of_element_located((By.ID, "ak_field_1")), 1)).select_by_value(str(random.randint(1, 31))) Select( self.waitElement( EC.visibility_of_element_located((By.ID, "ak_field_2")), 1)).select_by_value(str(random.randint(1, 12))) Select( self.waitElement( EC.visibility_of_element_located((By.ID, "ak_field_3")), 1)).select_by_value(str(random.randint(1970, 2000))) self.waitElement(EC.element_to_be_clickable((By.ID, "ak_field_4")), 1).click() if self.waitElement( EC.visibility_of_element_located((By.CLASS_NAME, "ak-title")), 120): creds = login + ':' + password print('Account created: ' + creds) return creds else: misc.ePrint('registration failed') return None