要提取
<a>标签内的所有文本值,例如 [‘A / D TC-55 SEALER’,’Carbocrylic 3356-1’] ,您必须为引入
WebDriverWait ,
visibility_of_all_elements_located()并且可以使用以下任一解决方案:
- 使用
CSS_SELECtOR
:
print([my_elem.get_attribute("innerHTML") for my_elem in WebDriverWait(driver, 5).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "li.topLevel[data-types='Acrylics'] h5>a[href^='/products/product-details/?prod=']")))])
- 使用
XPATH
:
print([my_elem.get_attribute("innerHTML") for my_elem in WebDriverWait(driver, 5).until(EC.visibility_of_all_elements_located((By.XPATH, "//li[@ and @data-types='Acrylics']//h5[@class]/a[starts-with(@href, '/products/product-details/?prod=')]")))])
- 注意 :您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)