在页面中获取页面内容的方式多种多样,介绍一种按照属性名称,并且使用多种方法获取
import time
from selenium import webdriver
driver = webdriver.Chrome()
driver.maximize_window()
wait = WebDriverWait(wd, 60)
driver.get('https://www.baidu.com')
wintitle = wait.until(expected_conditions.url_changes('https://www.baidu.com'))
print(wintitle)
time.sleep(1)
for link in driver.find_elements_by_xpath("//*[@src]"):
print (link.get_attribute('src'))
for class_attr in driver.find_elements_by_xpath("//*[@class]"):
print (class_attr.get_attribute('class'))
for link_href in driver.find_elements_by_xpath("//*[@href]"):
print (link_href.get_attribute('href'))
driver.quit()
按照xpath能够获取包含该属性的所有元素
|