Комментарии на веб-сайте, который вы разместили, находятся в iframe
, поэтому вам нужно будет переключиться на iframe
, прежде чем вы сможете найти комментарии.
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# first switch to the iframe
WebDriverWait(browser, 10).until(
EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe[contains(@title, 'fb:comments')]")))
# then get comments
comments_list = browser.find_elements_by_xpath("//span[@class='_5mdd']/span")
# iterate the comments
for comment in comments_list:
# print the comment text element -- the span which contains the commment text
print(comment.text)