I’m trying to scrape this site:https://www.vertexconnects.com/find-atc
I can’t seem to get the while loop to continue to click the “Load More” button after you put in any zipcode. The code seems to be failing on the locations line, getting each of the location results, with this error
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
Code below:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options = options)
action = ActionChains(driver)
driver.get("https://www.vertexconnects.com/find-atc")
driver.maximize_window()
wait = WebDriverWait(driver,5)
# Use below line only if you are getting the Accept/Reject cookies pop-up
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[contains(.,'Accept All')]"))).click()
location_textbox = wait.until(EC.presence_of_element_located((By.ID,"location-search-input")))
action.move_to_element(location_textbox).click().send_keys("10001").perform()
wait.until(EC.element_to_be_clickable((By.CLASS_NAME, "atc-finder-button"))).click()
while True:
try:
wait.until(EC_element_to_be_clickable((By.ID, "loadMore"))).click()
except:
break
print("done")
locations = wait.until(EC.visibility_of_all_elements_located((By.XPATH, "//div[@class='location-result']")))
for location in locations:
name = location.find_element(By.TAG_NAME, "h4").text()
address = location.find_element(By.CLASS_NAME, "address atc-finder-hospital-address").text()
phone_num = location.find_element(By.TAG_Name, "a").text
print(name, address, phone_num)