The login approach might be wrong
- using
Keys.RETURN or Keys.ENTER in password_field.send_keys(Keys.RETURN) may not work. when I tried, this didn't work and had to click on the Log In button.
I used:
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[onclick='return valLoginForm();']"))).click()
Here's the working solution:
from selenium.webdriver import Chrome, ChromeOptions
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
options = ChromeOptions()
options.add_argument("--start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option("useAutomationExtension", False)
driver = Chrome(options=options)
wait = WebDriverWait(driver, 10)
HOME_PAGE = 'https://fundfinder.panfoundation.org'
driver.get(HOME_PAGE)
# Wait for login form
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.login-wrap")))
# email_address
driver.find_element(By.CSS_SELECTOR, 'input#email').send_keys("your_email_id")
# password
driver.find_element(By.CSS_SELECTOR, 'input#phrase').send_keys("your_password")
# Click login when clickable
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a[onclick='return valLoginForm();']"))).click()
# Wait for fund list container after login
fund_list_container = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div#funds-tab>div>ul#fundList")))
# Click a fund item 'prostate cancer'(example)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'li[data-srch="prostate cancer"]'))).click()
# Wait for detail wrapper to render
fund_details = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.fund-detail-wrapper")))
# Extract data
data = []
for detail in fund_details.find_elements(By.CSS_SELECTOR, 'span.fund-detail'):
fund_link = detail.find_element(By.CSS_SELECTOR, 'span.fund-link a')
fund_status = detail.find_element(By.CSS_SELECTOR, 'span.fund-open i').get_attribute("class")
fund_name = detail.find_element(By.CSS_SELECTOR, 'span.fund-name').text
row = {
"fund_link": fund_link.get_attribute("href") if fund_link else "",
"fund_link_title": fund_link.text.strip() if fund_link else "",
"fund_status": "open" if "open" in fund_status else "lock",
"fund_name": fund_name,
}
data.append(row)
print(data)
output:
[
{
'fund_link': 'https://www.panfoundation.org/find-disease-fund/',
'fund_link_title': 'PAN Foundation',
'fund_status': 'lock',
'fund_name': 'Prostate cancer - Copay'
},
{
'fund_link': 'https://www.cancercare.org/copayfoundation#',
'fund_link_title': 'CancerCare Co-Payment Assistance Foundation',
'fund_status': 'lock',
'fund_name': 'Prostate Cancer - Copay'
},
{
'fund_link': 'https://www.healthwellfoundation.org/disease-funds/',
'fund_link_title': 'HealthWell Foundation',
'fund_status': 'lock',
'fund_name': 'Prostate Cancer - Medicare Access - Copay'
},
{
'fund_link': 'https://www.copays.org/funds',
'fund_link_title': 'Patient Advocate Foundation Co-Pay Relief',
'fund_status': 'lock',
'fund_name': 'Prostate Cancer - Copay'
},
{
'fund_link': 'https://www.copays.org/funds',
'fund_link_title': 'Patient Advocate Foundation Co-Pay Relief',
'fund_status': 'lock',
'fund_name': 'Prostate Cancer Health Equity Fund - Copay'
},
{
'fund_link': 'https://tafcares.org/program-listing/',
'fund_link_title': 'The Assistance Fund',
'fund_status': 'lock',
'fund_name': 'Prostate Cancer - Copay'
}
]
the above solution is self explanatory as I put the comments.
Note:
the full list of disease category gets loaded into the DOM after login, so there is no need to scroll.
similarly, to get the details of other disease category from the fund list, simply change the name in the line
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'li[data-srch="prostate cancer"]'))).click()
for example, for Batten Disease:
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'li[data-srch="batten disease"]'))).click()
- for the fund status, mostly, it's open or lock and this is visible by the class name,
fa fa-lock if status is lock and fa fa-lock-open if status is open.
- and as mentioned by others, the URL is not open in the APAC region I guess, had to use vpn to open and test it