3 回答

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超13個(gè)贊
這應(yīng)該打印所有帶有index_score的文章。
art = driver.find_elements_by_xpath("//article[@class='index__contentBlock__7vKo-']//span[@class='index__score__16yy9']")
for i in art:
print(i.text)

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超8個(gè)贊
您已經(jīng)收集了藝術(shù)的所有元素。
您所要做的就是:
art = driver.find_elements_by_xpath("//article[@class='index__contentBlock__7vKo-']")
for i in art:
print(i.text)
讓我知道這是否有效。

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超17個(gè)贊
使用Selenium提取評(píng)級(jí),例如2,0Python您必須引發(fā)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, "http://div[starts-with(@class, 'index__ratingBlock')]//span[starts-with(@class, 'index__score__')]")))])
控制臺(tái)輸出:
['2,0', '4,5', '3,8', '4,8', '2,8', '4,7', '3,2', '4,0', '4,9', '4,2']
注意:您必須添加以下導(dǎo)入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
添加回答
舉報(bào)