四、获取验证信息
# -*- coding:utf-8 -*-
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.keys import Keys
from time import sleep
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get("https://www.baidu.com/")
# 获取当前页面的标题
title = driver.title
print('title:' + title)
# 获取当前页面的url
url = driver.current_url
print(url)
# 获取当前页面的文本信息
driver.find_element_by_id("kw").send_keys("selenium")
driver.find_element_by_id("su").send_keys(Keys.ENTER)
sleep(2)
num = driver.find_element_by_xpath("//div[@id='tsn_inner']/div[2]/span").text
print(num)
driver.quit()
网友评论