Selenium_获取元素文本、属性值、尺寸(8)
from selenium import webdriver driver = webdriver.Chrome() driver.maximize_window() driver.get("https://www.baidu.com") # 定位属性 el = driver.find_element_by_xpath("//*[@href='http://news.baidu.com']") # 获取元素属性值 attr_c = el.get_attribute("class") # 获取元素的class属性值 print(attr_c) attr_t = el.get_attribute("target") # 获取元素的target属性值 print(attr_t) # 获取元素的文本信息 text = el.text print(text) # 获取元素尺寸大小 size = el.size print(size) driver.close()