获得验证信心的方式分别是:title URL text
from selenium import webdriver
from time import *
driver = webdriver.Chrome()
url = 'http://home.51cto.com/index?reback=http://9603083.blog.51cto.com/'
driver.get(url)
#打印当前页面
title = driver.title
print(title)
#打印当前页面URL
now_url = driver.current_url
print(now_url)
#执行登陆
driver.find_element_by_xpath('//*[@id="loginform-username"]').clear()
driver.find_element_by_xpath('//*[@id="loginform-username"]').send_keys('91ctt')
driver.find_element_by_xpath('//*[@id="loginform-password"]').clear()
driver.find_element_by_xpath('//*[@id="loginform-password"]').send_keys('CTT1106648034')
driver.find_element_by_xpath('//*[@id="login-form"]/div[3]/input').click()
sleep(3)
#再次打印当前页面
title = driver.title
print(title)
#打印当前页面URL
now_url = driver.current_url
print(now_url)
#获取用户名
usr = driver.find_element_by_xpath('/html/head/meta[3]').text
print(usr)
sleep(3)
driver.quit()