I made this Selenium script as a practice to scrape JS heavy pages.
The programs, start up a WebDriver enters a website, then press a button so they all show up then I want just pull some data, the names of the clubs, but there is a problem.
It just prints [], can someone tell me what I'm doing wrong here?
And my goal is to get the names of the clubs like Acadiana Kennel Club, Inc.
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
option = webdriver.ChromeOptions()
option.add_argument(" - incognito")
browser = webdriver.Chrome('/home/djurovic/Desktop/Linux ChromeDriver/chromedriver', chrome_options=option)
browser.get('https://webapps.akc.org/club-search/?fbclid=IwAR1X9TkSI49bHgH3w4VmgrMS05sxLbbazaMO17Q1rEfVq7Pj4Ze66B4hdLM#/agility')
timeout = 20
buttonXpath = '//a[@class="button"]'
namesXpath = '//*[@class="ng-binding"]/text()'
try:
buttonElement = WebDriverWait(browser, timeout).until(lambda browser: browser.find_element_by_xpath(buttonXpath))
buttonElement.click()
clubNames = WebDriverWait(browser, timeout).until(lambda browser: browser.find_elements_by_xpath(namesXpath))
print(clubNames)
except TimeoutException:
print('Timed out waiting for page to load')
browser.quit()
for clubName in clubNames: print(clubName)?