0

I have a news website to scrape. But after scraping the first page, I need to click on "load more" which is a link to view other news and then scrape. Where I am encountering an issue is that I can't seem to click on "load more" because it doesn't have a "href". I have tried all possible resources, but they have all worked to no avail. Please, kindly help me out with this. Thank you. I have attached the code I used and the link to the website.

Code trials:

pip install webdriver-manager

from selenium.webdriver.common.keys import Keys
import time
from webdriver_manager.chrome import ChromeDriverManager
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import NoSuchElementException

driver = webdriver.Chrome(ChromeDriverManager().install())
url = 'https://www.legit.ng/tag/road-accidents-in-nigeria/'
driver.get(url)
link = driver.find_element_by_link_text("Entertainment")
link.click()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
zion
  • 1
  • 2

1 Answers1

1

To click on the element with text as Load more you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using XPATH and text()[contains()]:

    driver.get("https://www.legit.ng/tag/road-accidents-in-nigeria/")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[text()[contains(.,'Load more')]]"))).click()
    
  • Using XPATH and contains():

    driver.get("https://www.legit.ng/tag/road-accidents-in-nigeria/")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[contains(., 'Load more')][./p[text()]]"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • First, thank you for your comment. However, I got the following error while running the code; ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (686, 458). Other element would receive the click: ... (Session info: chrome=97.0.4692.99) – zion Jan 22 '22 at 02:45