I'm trying to scrape Facebook posts off a site of one band, but I get an error while searching in an iterated WebElement:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"class name","selector":"userContent"}
The posts are found successfully, but the code breaks while searching for post_text_element. I tried searching by XPATH as well, but the result was same.
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
SITE_URL = 'https://www.facebook.com/pg/mnagaazdorp/posts/'
POSTS_XPATH = "//*[contains(@class, '_4-u2') and contains(@class, '_4-u8')]"
POST_TEXT_CLASS = "userContent"
TIMEOUT = 1
CHROME_DRIVER_PATH = "C:\\Users\\tonda\\Documents\\chromedriver.exe"
browser = webdriver.Chrome(executable_path=CHROME_DRIVER_PATH)
browser.get(SITE_URL)
wait = WebDriverWait(browser, TIMEOUT)
posts = browser.find_elements_by_xpath(POSTS_XPATH)
for post in posts:
post_text_element = post.find_element_by_class_name(POST_TEXT_CLASS)
print(post_text_element.text)
browser.quit()