I'm trying to scrape this website
https://maroof.sa/BusinessType/BusinessesByTypeList?bid=14&sortProperty=BestRating&DESC=True There is a button to load more content when you click it, it displays more content without changing the URL I had made a piece of code to load all the content first then extract all the URLs of the data I need then go to each link and scrape the data
url = "https://maroof.sa/BusinessType/BusinessesByTypeList?bid=26&sortProperty=BestRating&DESC=True"
driver = webdriver.Chrome()
driver.get(url)
# button = driver.find_element_by_xpath('//*[@id="loadMore"]/button')
num = 1
while num <= 507:
sleep(4)
button = WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="loadMore"]/button')))
button.click()
print(num)
num += 1
links = [l.get_attribute('href') for l in WebDriverWait(driver, 40).until(EC.visibility_of_all_elements_located((By.XPATH, '//*[@id="list"]/a')))]
it seems to work but sometimes it doesn't click on the button that loads the content it accidentally click on something else and makes an error and i have to start over again Can you help me?