The use of selenium analog Taobao landing

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By


class TaoBaoLogin(object):

__init __ DEF (self, the Account, password):
self.options = webdriver.ChromeOptions ()
# set developer mode
self.options.add_experimental_option ( "excludeSwitches", [ 'enable-Automation'])
# no load picture, quick access to
self .options.add_experimental_option ( "Prefs", { "profile.managed_default_content_settings.images": 2})
self.driver = webdriver.Chrome (Options = self.options)
self.url = "https://login.taobao.com/ Member / login.jhtml "
# waiting for the browser to load data
self.wait = WebDriverWait (self.driver, 10, 0.5)
self.account = Account
self.password password =

def __del__(self):
self.driver.quit()

def login(self):
self.driver.get(self.url)
try:
pwd_login_elem = self.wait.until(
EC.element_to_be_clickable((By.XPATH, "//div[@id='J_QRCodeLogin']/div[@class='login-links']/a[1]")))
pwd_login_elem.click()

wb_login_elem = self.wait.until(EC.element_to_be_clickable((By.CLASS_NAME, "weibo-login")))
wb_login_elem.click()

account_elem = self.wait.until(EC.presence_of_element_located((By.NAME,"username")))
account_elem.send_keys(self.account)

pwd_elem = self.wait.until(EC.presence_of_element_located((By.NAME,"password")))
pwd_elem.send_keys(self.password)

submit = self.wait.until(EC.element_to_be_clickable((By.XPATH,"//a[@class='W_btn_g']")))
submit.click()

print ( "login success")

the except:
Print ( "login failed")


__name__ == IF '__main__':
username = the INPUT ( "Please enter your micro-blog account >>")
password = the INPUT ( "Please enter your password microblogging >>")
TaoBaoLogin (username, password) your .login ()
--------------------- 

Guess you like

Origin www.cnblogs.com/ly570/p/11007571.html