selenium登录实验楼
程序员文章站
2022-03-21 21:27:55
```Python
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from se... ......
from selenium import webdriver from selenium.webdriver.common.by import by from selenium.webdriver.support.wait import webdriverwait from selenium.webdriver.support import expected_conditions as ec username = '' # 输入账号 password = '' # 输入密码 driver = webdriver.chrome() driver.maximize_window() wait = webdriverwait(driver, 10) driver.get('https://www.shiyanlou.com') # 登录入口 wait.until(ec.element_to_be_clickable((by.css_selector, '#__layout > div > div.body > div.home > div > div.container > div.row > div > div.home-header > div > div > li.nav-item.base-nav-item.sign-in-btn > a'))).click() # 输入账号密码 wait.until(ec.presence_of_element_located((by.css_selector, '#__bvid__364'))).send_keys(username) wait.until(ec.presence_of_element_located((by.css_selector, '#__bvid__365'))).send_keys(password) # 勾选自动登录 wait.until(ec.presence_of_element_located((by.css_selector, '#sign-modal___bv_modal_body_ > div:nth-child(3) > form > div.remember > div > label'))).click() # 点击登录按钮 wait.until(ec.element_to_be_clickable((by.css_selector, '#sign-modal___bv_modal_body_ > div:nth-child(3) > form > button'))).click()
上一篇: 栈的应用
下一篇: vue移动端微信授权登录插件封装的实例