Please Help. I have been working on this for days and I cannot figure out where I am getting this wrong. I am trying to loop through a table but i am only getting the first row and nothing else. What am i doing wrong? Im guessing my loop might be the culprit but i am still new to python and cannot figure it out. I want to end up with everything in an excel document
from numpy import fabs
from selenium import webdriver
from selenium.webdriver.common.by import By
import pandas as pd
driver = webdriver.Chrome(r"C:\Users\noree\OneDrive\Documents\chromedriver.exe")
driver.get('https://www.depositaccounts.com/banks/assets.aspx?instType=&stateType=hq&state=')
driver.maximize_window()
#get url largest banks and credit unions by assets
#Show all entries - xpath for show all button
show_all_button = driver.find_element(By.XPATH,'//*[@id="results"]/div/a')
# Click 'Show all' Button
show_all_button.click()
#scrape the tables
rank = driver.find_elements(By.XPATH, '//*[@id="assetsTable"]/tbody/tr[2]/td[1]')
financial_institution = driver.find_elements(By.XPATH,'//table[@id="assetsTable"]/tbody/tr[2]/td[2]/a')
headquarters = driver.find_elements(By.XPATH, '//tbody/tr[2]/td[3]')
assets = driver.find_elements(By.XPATH, '//tbody/tr[2]/td[4]')
asset_growth = driver.find_elements(By.XPATH, '//tbody/tr[2]/td[5]')
branches = driver.find_elements(By.XPATH, '//tbody/tr[2]/td[6]')
states_with_branches = driver.find_elements(By.XPATH, '//tbody/tr[2]/td[7]')
employees = driver.find_elements(By.XPATH, '//tbody/tr[2]/td[7]')
customer_accounts = driver.find_elements(By.XPATH, '//tbody/tr[2]/td[8]')
#create empty list
bank_results = []
for i in range(len(rank)):
temporary_data={
'Rank': rank[i].text,
'Financial Institution': financial_institution[i].text,
'Headquarters': headquarters[i].text,
'Assets': assets[i].text,
'Asset Growth': asset_growth[i].text,
'Branches': branches[i].text,
'States with Branches': states_with_branches[i].text,
'Employees': employees[i].text,
'Customer Accounts': customer_accounts[i].text
}
bank_results.append(temporary_data)
df_data = pd.DataFrame(bank_results)
df_data