I try to load all comments from this site to scrape them but i cant figure out how to load them all.
When i run my code i get error in console it says:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable( File "C:\Users\Jakub\dev\rok_quests\rok_quests\Lib\site-packages\selenium\webdriver\support\wait.py", line 95, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
Doesnt it mean it doesnt find a button or it cant click on it ?
the url i use:
The code here is meant to load all comments from comments section then i will get page_source and scrape .
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from bs4 import BeautifulSoup
import time
def scrape_comments(url):
# Set up Chrome driver options
chrome_options = Options()
chrome_options.add_argument("start-maximized")
chrome_options.add_argument('disable-infobars')
chrome_options.add_argument("--block-notifications")
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(options=chrome_options)
wait = WebDriverWait(driver, 10)
comments = []
try:
# Open the website
driver.get(url)
get_url = driver.current_url
wait.until(EC.url_to_be(url))
if get_url != url:
raise Exception('Site url doesnt match')
WebDriverWait(driver, 20).until(EC.visibility_of_element_located(
(By.CSS_SELECTOR, ".wpd-comment-text")))
while True:
try:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable(
(By.XPATH, "/html/body/div[3]/div/div[1]/main/div/div[2]/div[2]/div[3]/div[3]/div[51]/div/button"))).click()
print("clicked")
except TimeoutError:
print("No more to load")
break
print(driver.page_source)
return comments
finally:
# Close the web driver
driver.quit()