I've created a script in python together with selenium to parse three fields franking credit
,gross divident
and further information
from a table available in a website. The last two fields are revealed only when the browser is made to click on a circular yellow button having plus sign within it.
However, when the buttons are clicked, they turn into red which indicates that the information got displayed.
My script can click on all the buttons but it can't scrape the three fields from that table.
I've attached an image to show you how it really looks like.
I know if I send a post http requests with concerning payload to this https://www.sharedividends.com.au/wp-content/custom/ajaxfile.php?code=MLT
, I can get all the tabular fields in json but that is not how I wanna solve this.
I've tried with:
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
url = "https://www.sharedividends.com.au/mlt-dividend-history/"
driver = webdriver.Chrome()
driver.get(url)
table = driver.find_element_by_css_selector("#divTable")
driver.execute_script("arguments[0].scrollIntoView();",table)
for items in driver.find_elements_by_css_selector("td.sorting_1"):
driver.execute_script("arguments[0].scrollIntoView();",items)
items.click()
for elems in driver.find_elements_by_css_selector("#divTable tbody tr"):
franking_credit = elems.find_elements_by_css_selector("td")[5].text
gross_divident = elems.find_elements_by_css_selector("td")[6].text
further_info = elems.find_elements_by_css_selector("td")[7].text
print(franking_credit,gross_divident,further_info)
driver.quit()
Whe I run the above script it throws this error IndexError: list index out of range
pointing at franking_credit =
this line.
This is how that table looks like. I've marked the three fields in that table within the image below which I'm interested in.
How can I parse the three fields from that table?