Issue
I am trying to get the text data from the below website:-
https://www.lemoyne.edu/Give/Information-for-Donors/Honor-Roll/1954
Any suggestion/help would be appreciated. Thanks in advance!!
driver = webdriver.Chrome("chromedriver.exe")
driver.maximize_window()
driver.get("https://www.lemoyne.edu/Give/Information-for-Donors/Honor-Roll/1954")
time.sleep(10)
donors= driver.find_elements("xpath",'//div[@class = "container"]/div[@class="donorcolumn"]/p')
donors
##Result:- Empty List []
for donor in donors:
print(donor.get_attribute("innerHTML"))
##Result:- Empty List []
for donor in donors:
print(donor.text)
## Result:- Empty List []
Expectation:-
The Hon. Salvatore J. Arrigo Jr. '54 and Mrs. Elizabeth J. Arrigo (35) President's Club Annual Fund Previous President's Club Member
Margaret A. Dwyer '54, L.C.H.D. '94 (35) President's Club Previous President's Club Member
Frances Morrison Scott Estate (1) Previous President's Club Member
Rosemary T. Fatcheric '54 (12)
Jo-An Feyerabend '54 (35)
James H. Greiner '54 (11) Annual Fund
Charles R. Nojaim '54 and Patricia Nojaim (22)
Marie Dinehart Rathbun '54 (22)
Audrey Zillioux Rich '54 (30) Annual Fund
David G. Schoeneck '54 and Therese Sharpe Schoeneck '54 (25) Annual Fund
John H. Senecal '54 (14)
John B. Vita '54 and Mary M. Vita (1)
Eugene P. Vukelic '54 (8) President's Club Annual Fund Previous President's Club Member
Solution
If you notice the HTML, desired elements are wrapped withing an iframe
, you need to switch into the frame and then perform other actions, use below code to switch to iframe
:
wait = WebDriverWait(driver, 10)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, "dnn_ctr11646_IFrame_htmIFrame")))
Full code:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.lemoyne.edu/Give/Information-for-Donors/Honor-Roll/1954")
wait = WebDriverWait(driver, 10)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, "dnn_ctr11646_IFrame_htmIFrame")))
donors = wait.until(EC.visibility_of_all_elements_located((By.XPATH, "//div[@class = 'container']/div[@class='donorcolumn']/p")))
for donor in donors:
print(donor.get_attribute("innerHTML"))
for donor in donors:
print(donor.text)
Answered By - Shawn
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.