find_elements_by_css_XXX(value) 定位一组元素,该方法返回一个元素对象列表
一、代码如下
导包
from selenium import webdriver
import time
创建一个浏览器
driver = webdriver.Chrome()
访问百度
url = 'https://www.baidu.com/'
driver.get(url)
定位到输入框
el_su = driver.find_element_by_id('kw')
el_su.send_keys('selenuim')
定位到搜索按钮
el_sub = driver.find_element_by_id('su')
el_sub.click()
定位一组元素
el_list = driver.find_elements_by_css_selector('div[id="content_left"]>div>h3>a')
print(el_list)
time.sleep(2)
driver.close()
二、代码如下
body > div.list-wrap > div.list-box > ul > li:nth-child(1) > div.des > h2 > a
from selenium import webdriver
driver = webdriver.Chrome()
url = 'https://sz.58.com/chuzu/?PGTID=0d100000-0000-4181-3f16-7870e97675ff&ClickID=1'
driver.get(url)
搜索一组搜索结果
el_list = driver.find_element_by_css_selector('body > div.list-wrap > div.list-box > ul > li:nth-child(1) > div.des > h2 > a')
print(el_list)
网友评论