慕慕森
使用Selenium提取评级,例如2,0Python您必须引发WebDriverWait,并且visibility_of_all_elements_located()可以使用以下任一定位器策略:使用CSS_SELECTOR和get_attribute("innerHTML"):driver.get('https://www.kununu.com/de/volkswagen/kommentare/100')print([my_elem.get_attribute("innerHTML") for my_elem in WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "div[class^='index__ratingBlock'] span[class^='index__score__']")))])使用XPATH和文本属性:driver.get('https://www.kununu.com/de/volkswagen/kommentare/100')print([my_elem.text for my_elem in WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.XPATH, "//div[starts-with(@class, 'index__ratingBlock')]//span[starts-with(@class, 'index__score__')]")))])控制台输出:['2,0', '4,5', '3,8', '4,8', '2,8', '4,7', '3,2', '4,0', '4,9', '4,2']注意:您必须添加以下导入:from selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support import expected_conditions as EC