010-利用Selenium+python自动输入博客账号密码登录
from selenium import webdriver import time def OpenUrl(): # 访问网址 driver.get(url) def Login(): # 查询登录按钮 driver.find_element_by_link_text("登录").click() time.sleep(1) # 输入账号 driver.find_element_by_id("LoginName").send_keys(Name) # 输入密码 driver.find_element_by_id("Password").send_keys(Password) time.sleep(2) # 点击登录按钮 driver.find_element_by_id("submitBtn").click() time.sleep(2) if __name__ == "__main__": # 打开谷歌浏览器 driver = webdriver.Chrome() url = "https://www.cnblogs.com" Name = "XXXXXX@qq.com" Password = "XXXXXX" OpenUrl() Login() driver.quit()
存在遗漏的地方:点击登录时,如果弹出了登录校验,没有进行处理