# 导包 from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC # 定义driver driver=webdriver.Chrome() # 打开浏览器 driver.get("https://www.baidu.com") # 获取元素 # 分离出地位的元素 loc="#s-hotsearch-wrapper [class='title-content-title']" # <class 'str'> print(type(loc)) elements=WebDriverWait(driver,10).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR,loc))) print(elements) for e in elements: print(e.text) # 退出 driver.quit()
标签:定位,elements,webdriver,selenium,元素,driver,字符串,import,loc From: https://www.cnblogs.com/haha1988/p/17734865.html