zoukankan      html  css  js  c++  java
  • 使用selenium实现模拟淘宝登陆

    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):

    def __init__(self, account, password):
    self.options = webdriver.ChromeOptions()
    # 设置开发者模式
    self.options.add_experimental_option("excludeSwitches", ['enable-automation'])
    # 不加载图片,快速访问
    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"
    # 等待浏览器加载数据
    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("登陆成功")

    except:
    print("登陆失败")


    if __name__ == '__main__':
    username = input("请输入你的微博账号>>")
    password = input("请输入你的微博密码>>")
    TaoBaoLogin(username, password).login()
    --------------------- 

  • 相关阅读:
    React开发实时聊天招聘工具 -第六章 登陆注册(2)
    React开发实时聊天招聘工具 -第六章 登陆注册(1)
    温习 socket http tcp
    高阶组件简介
    计算机组成原理(7)——输入、输出系统
    计算机组成原理(6)——总线
    计算机组成原理(5)——中央处理器
    计算机组成原理(4)——指令系统
    计算机组成原理(3)——存储层次结构
    计算机组成原理(2)——数据的表示与运算
  • 原文地址:https://www.cnblogs.com/ly570/p/11007571.html
Copyright © 2011-2022 走看看