6-selenium-定位一组元素
import time from selenium import webdriver ''' 定位一组元素find_eleniums 获取元素属性 .get_attribute('name')
补充一下css选择器:
id 表示为 #
class 表示为 .
dir.kw>a
''' driver = webdriver.Chrome() driver.get('http://www.baidu.com') driver.find_element_by_css_selector("#kw").send_keys('测试面试') driver.find_element_by_css_selector("#su").click() time.sleep(2) a_list = driver.find_elements_by_css_selector("h3.t>a") print(a_list) for x in a_list: link = x.get_attribute('href') print(link)