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()
#scrap 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
CodePudding user response:
You dont need to iterate to each column. You can simple use entire table id locator which will print the entire table data in one go. As it will print the table data with table name, so even if the values appears in table dynamically, it wouldn't impact.
First Approach: -> Print the entire table in one go with the help of table name in locator
driver = webdriver.Chrome(PATH)
driver.get("https://www.depositaccounts.com/banks/assets.aspx?instType=&stateType=hq&state=")
print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.ID, "assetsTable"))).text)
Output:
Rank Financial Institution Headquarters Assets Asset Growth
(vs. prior year)
Branches States
w/ Branches
Employees Customer Accounts
1 Chase Bank Columbus, OH $3,190,100,000,000 11.54% 5,037 42 199,245 65,003,685
2 Bank of America Charlotte, NC $2,350,294,000,000 8.03% 4,315 38 138,120 118,494,272
3 Wells Fargo Bank San Francisco, CA $1,776,718,000,000 -1.29% 4,900 40 225,474 68,140,861
4 Citi New York, NY $1,693,227,000,000 3.51% 921 12 171,715 21,143,960
5 US Bank Minneapolis, MN $547,852,681,000 2.11% 2,275 27 66,399 37,558,209
6 Truist Charlotte, NC $510,294,000,000 3.19% 2,509 0 48,883 14,739,614
7 PNC Bank Wilmington, DE $453,973,605,000 -0.29% 2,098 26 50,995 18,916,469
8 TD Bank Wilmington, DE $415,513,499,000 7.59% 1,155 16 24,333 22,745,805
9 The Bank of New York Mellon New York, NY $384,538,000,000 6.91% 25 6 39,524 144,034
10 Capital One Mclean, VA $369,046,976,000 1.45% 333 8 31,497 19,841,995
11 Charles Schwab Bank Westlake, TX $358,095,000,000 18.35% N/A N/A 743 1,521,892
12 Marcus by Goldman Sachs New York, NY $351,163,000,000 19.53% N/A N/A 2,449 1,954,275
13 State Street Bank and Trust Company Boston, MA $322,958,000,000 14.29% 3 1 29,696 40,021
14 Fifth Third Bank (OH) Cincinnati, OH $203,979,275,000 1.32% 1,139 13 19,377 6,494,546
15 HSBC Tysons, VA $194,764,172,000 -7.71% 164 9 3,610 1,311,696
16 Citizens Bank (RI) Providence, RI $185,036,173,000 2.81% 965 11 17,320 5,092,199
17 KeyBank Cleveland, OH $178,935,686,000 5.10% 1,029 16 17,696 4,338,894
18 Huntington National Bank Columbus, OH $174,866,037,000 32.36% 1,028 8 19,803 7,360,681
19 Morgan Stanley Bank, National Association Salt Lake City, UT $173,043,000,000 3.45% 1 1 299 1,197
20 The Northern Trust Company Chicago, IL $171,869,980,000 12.19% 57 17 20,457 145,413
21 Ally Bank Sandy, UT $170,075,000,000 -1.64% N/A N/A 8,920 4,478,777
22 First Republic Bank San Francisco, CA $161,646,734,000 20.63% 82 7 6,065 684,902
23 Silicon Valley Bank Santa Clara, CA $161,200,274,000 47.59% 24 1 4,078 86,077
24 BMO Harris Bank Chicago, IL $159,838,645,000 3.99% 529 8 10,357 2,353,214
25 Regions Bank Birmingham, AL $154,735,000,000 7.30% 1,315 15 18,738 6,983,261
26 M&T Bank Buffalo, NY $150,227,852,000 7.37% 689 9 16,325 3,695,538
27 Navy Federal Credit Union Vienna, VA $147,898,794,000 N/A 333 31 18,678 22,596,634
28 Morgan Stanley Trust New York, NY $135,856,000,000 24.53% 1 2 908 423
29 Union Bank (San Francisco, CA) San Francisco, CA $133,207,181,000 -2.25% 296 3 13,258 1,649,029
30 American Express National Bank Salt Lake City, UT $126,565,746,000 -8.70% N/A N/A 1,578 1,646,650
31 USAA Bank San Antonio, TX $115,631,179,000 12.79% N/A N/A 16,073 12,380,695
32 Discover Bank Greenwood, DE $108,936,256,000 -2.94% N/A N/A 11,005 6,404,620
33 Bank of the West San Francisco, CA $99,178,981,000 -0.82% 533 19 9,049 1,882,871
34 Signature Bank New York, NY $97,209,737,000 37.92% 36 4 1,795 161,502
35 Santander Bank, N.A Wilmington, DE $95,192,570,000 7.82% 516 9 8,566 3,162,380
36 UBS Bank USA Salt Lake City, UT $94,957,060,000 20.38% 1 0 481 4,191
37 Comerica Bank Dallas, TX $88,331,000,000 4.40% 434 5 6,755 1,102,557
38 First Horizon Bank Memphis, TN $87,574,096,000 44.66% 0 0 7,551 1,718,324
39 Zions Bank Salt Lake City, UT $87,208,406,000 12.34% 419 11 9,727 1,499,774
40 City National Bank (CA) Los Angeles, CA $84,955,426,000 15.87% 75 9 5,369 281,135
41 Synchrony Bank Draper, UT $81,927,000,000 -3.91% N/A N/A 8,810 2,546,222
42 East West Bank Pasadena, CA $59,838,864,000 17.43% 117 7 3,161 567,136
43 New York Community Bank Hicksville, NY $57,444,945,000 5.67% 237 5 2,785 730,987
44 First Citizens Bank (NC) Raleigh, NC $55,098,938,000 13.20% 524 19 6,654 1,688,254
45 Synovus Bank Columbus, GA $54,872,532,000 1.52% 284 5 4,772 813,456
46 State Employees' Credit Union (NC) Raleigh, NC $49,939,131,000 9.51% 277 1 6,886 5,197,698
47 CIT Bank Pasadena, CA $49,309,230,000 -13.10% N/A N/A 3,470 589,713
48 Western Alliance Bank Phoenix, AZ $49,068,916,000 34.93% 36 1 3,205 152,964
49 BOK Financial Tulsa, OK $46,909,545,000 2.74% 0 2 4,573 696,415
50 Frost Bank San Antonio, TX $46,734,243,000 15.61% 162 1 4,528 739,230
51 CIBC Bank USA Chicago, IL $45,147,152,000 14.11% 24 4 1,720 125,252
52 Deutsche Bank Trust Company Americas New York, NY $42,726,000,000 -5.49% 2 1 431 9,903
53 Valley Passaic, NJ $41,294,181,000 -0.99% 213 4 3,130 717,808
54 South State Bank Winter Haven, FL $40,262,683,000 6.31% 285 3 5,203 1,132,018
55 First National Bank of Pennsylvania Pittsburgh, PA $38,437,671,000 1.99% 334 8 3,867 1,102,488
56 TIAA Bank Jacksonville, FL $38,435,437,000 -10.34% N/A N/A 1,826 371,115
57 UMB Bank, National Association Kansas City, MO $36,376,318,000 18.43% 98 8 2,765 1,155,261
58 Prosperity Bank (TX) El Campo, TX $36,098,031,000 8.65% 294 2 3,724 784,990
59 BankUnited Miami Lakes, FL $35,583,698,000 2.72% 70 2 1,425 154,306
60 Texas Capital Bank Dallas, TX $35,217,132,000 -3.66% 10 1 1,557 33,150
61 Pinnacle Bank (TN) Nashville, TN $35,216,904,000 5.74% 54 5 2,706 389,620
62 Pacific Western Bank Beverly Hills, CA $34,820,512,000 21.49% 74 2 2,055 138,707
63 Raymond James Bank Saint Petersburg, FL $34,576,165,000 15.94% 1 1 275 6,006
64 Associated Bank, NA Green Bay, WI $34,102,811,000 -3.81% 231 3 4,007 1,108,550
65 Webster Bank Waterbury, CT $33,737,378,000 3.01% 134 4 2,937 1,276,844
66 Commerce Bank Kansas City, MO $33,712,939,000 9.81% 167 5 4,433 1,061,825
67 MidFirst Bank Oklahoma City, OK $31,048,180,000 21.63% 78 3 2,905 537,495
68 Umpqua Bank Roseburg, OR $30,290,285,000 2.17% 227 5 3,755 749,287
69 Sterling National Bank (NY) Pearl River, NY $29,057,043,000 -5.54% 75 1 1,491 509,524
70 Sallie Mae Bank Salt Lake City, UT $28,835,767,000 -5.20% N/A N/A 1,623 316,959
71 Barclays Wilmington, DE $28,773,000,000 -12.61% N/A N/A 2,825 762,267
72 BECU (Boeing Employees Credit Union) Tukwila, WA $28,643,913,000 13.58% 59 2 2,494 2,856,401
73 PenFed Credit Union McLean, VA $27,652,680,000 6.25% 41 14 3,128 3,225,727
74 Bancorp South Tupelo, MS $27,616,695,000 15.94% 324 9 4,835 764,441
75 United Bank (VA) Fairfax, VA $27,158,306,000 3.49% 205 3 2,944 587,082
76 Flagstar Bank Troy, MI $27,043,034,000 -1.43% 158 5 5,503 520,394
77 Investors Bank Short Hills, NJ $26,765,369,000 -1.49% 147 2 1,688 488,462
78 FirstBank (Lakewood, CO) Lakewood, CO $26,751,618,000 15.89% 109 3 2,554 995,106
79 Bank OZK Little Rock, AR $26,605,938,000 0.85% 234 7 2,588 592,512
80 Arvest Bank Fayetteville, AR $26,237,693,000 11.51% 243 4 6,237 1,582,807
81 Fulton Bank, National Association Lancaster, PA $25,922,789,000 5.52% 203 5 3,192 748,432
82 SchoolsFirst Federal Credit Union Santa Ana, CA $25,874,585,000 16.43% 68 1 2,365 2,831,491
83 First National Bank of Omaha Omaha, NE $25,479,621,000 6.25% 50 4 4,128 937,545
84 First Hawaiian Bank Honolulu, HI $24,246,092,000 5.17% 54 1 2,087 540,513
85 Old National Bank Evansville, IN $23,577,324,000 6.69% 100 5 2,230 717,783
86 Simmons Bank Pine Bluff, AR $23,379,838,000 6.52% 211 6 2,764 602,715
87 Bank of Hawaii Honolulu, HI $22,642,103,000 12.81% 52 1 2,085 622,377
88 Ameris Bank Atlanta, GA $21,791,489,000 9.20% 168 5 2,686 456,304
89 FirstBank (FL) Miami, FL $21,361,138,000 34.07% 84 1 3,172 660,279
90 Pacific Premier Bank Irvine, CA $20,533,652,000 0.09% 41 5 1,521 156,494
91 Glacier Bank Kalispell, MT $20,475,522,000 17.48% 55 1 2,982 709,289
92 City National Bank (FL) Miami, FL $20,235,407,000 13.78% 32 1 910 75,134
93 Atlantic Union Bank Richmond, VA $19,953,865,000 1.24% 129 3 1,885 497,101
94 WaFd Bank Seattle, WA $19,651,718,000 7.49% 220 8 2,058 462,584
95 Customers Bank Phoenixville, PA $19,634,826,000 8.87% 13 3 605 2,379,856
96 Cathay Bank Los Angeles, CA $19,330,759,000 0.49% 59 8 1,173 273,675
97 Wells Fargo National Bank West Las Vegas, NV $19,275,160,000 11.05% 1 1 0 347,668
98 First Interstate Bank Billings, MT $18,879,309,000 13.07% 147 6 2,391 462,898
99 United Community Bank (GA) Blairsville, GA $18,867,020,000 20.62% 148 4 2,434 512,789
100 Mechanics Bank (CA) Walnut Creek, CA $18,797,454,000 -0.38% 124 1 1,827 363,560
Second Approach:
If you want to play with the table, then play with the locator. No need to write looping for all table itmes.
driver = webdriver.Chrome(PATH)
tabelHeaderLocator = driver.find_element(By.CSS_SELECTOR, "#assetsTable > tbody > tr:nth-child(1)") ->This line will fetch the entire first column which is header
print(re.sub(r"\s ", '|', tabelHeaderLocator.text.strip())) -> You can prettify it
tableData = driver.find_elements(By.CSS_SELECTOR, "#assetsTable > tbody > tr") ->It will fetch all the rows
del tableData[:1] ->Deleting first row as this row is again table header which we printed seperately
for element in tableData: -> Now from your all row print the text values
print(element.text)
Output:
Rank|Financial|Institution|Headquarters|Assets|Asset|Growth|(vs.|prior|year)|Branches|States|w/|Branches|Employees|Customer|Accounts
1 Chase Bank Columbus, OH $3,190,100,000,000 11.54% 5,037 42 199,245 65,003,685
2 Bank of America Charlotte, NC $2,350,294,000,000 8.03% 4,315 38 138,120 118,494,272
3 Wells Fargo Bank San Francisco, CA $1,776,718,000,000 -1.29% 4,900 40 225,474 68,140,861
4 Citi New York, NY $1,693,227,000,000 3.51% 921 12 171,715 21,143,960
5 US Bank Minneapolis, MN $547,852,681,000 2.11% 2,275 27 66,399 37,558,209
6 Truist Charlotte, NC $510,294,000,000 3.19% 2,509 0 48,883 14,739,614
7 PNC Bank Wilmington, DE $453,973,605,000 -0.29% 2,098 26 50,995 18,916,469
8 TD Bank Wilmington, DE $415,513,499,000 7.59% 1,155 16 24,333 22,745,805
9 The Bank of New York Mellon New York, NY $384,538,000,000 6.91% 25 6 39,524 144,034
10 Capital One Mclean, VA $369,046,976,000 1.45% 333 8 31,497 19,841,995
11 Charles Schwab Bank Westlake, TX $358,095,000,000 18.35% N/A N/A 743 1,521,892
12 Marcus by Goldman Sachs New York, NY $351,163,000,000 19.53% N/A N/A 2,449 1,954,275
13 State Street Bank and Trust Company Boston, MA $322,958,000,000 14.29% 3 1 29,696 40,021
14 Fifth Third Bank (OH) Cincinnati, OH $203,979,275,000 1.32% 1,139 13 19,377 6,494,546
15 HSBC Tysons, VA $194,764,172,000 -7.71% 164 9 3,610 1,311,696
16 Citizens Bank (RI) Providence, RI $185,036,173,000 2.81% 965 11 17,320 5,092,199
17 KeyBank Cleveland, OH $178,935,686,000 5.10% 1,029 16 17,696 4,338,894
18 Huntington National Bank Columbus, OH $174,866,037,000 32.36% 1,028 8 19,803 7,360,681
19 Morgan Stanley Bank, National Association Salt Lake City, UT $173,043,000,000 3.45% 1 1 299 1,197
20 The Northern Trust Company Chicago, IL $171,869,980,000 12.19% 57 17 20,457 145,413
21 Ally Bank Sandy, UT $170,075,000,000 -1.64% N/A N/A 8,920 4,478,777
22 First Republic Bank San Francisco, CA $161,646,734,000 20.63% 82 7 6,065 684,902
23 Silicon Valley Bank Santa Clara, CA $161,200,274,000 47.59% 24 1 4,078 86,077
24 BMO Harris Bank Chicago, IL $159,838,645,000 3.99% 529 8 10,357 2,353,214
25 Regions Bank Birmingham, AL $154,735,000,000 7.30% 1,315 15 18,738 6,983,261
26 M&T Bank Buffalo, NY $150,227,852,000 7.37% 689 9 16,325 3,695,538
27 Navy Federal Credit Union Vienna, VA $147,898,794,000 N/A 333 31 18,678 22,596,634
28 Morgan Stanley Trust New York, NY $135,856,000,000 24.53% 1 2 908 423
29 Union Bank (San Francisco, CA) San Francisco, CA $133,207,181,000 -2.25% 296 3 13,258 1,649,029
30 American Express National Bank Salt Lake City, UT $126,565,746,000 -8.70% N/A N/A 1,578 1,646,650
31 USAA Bank San Antonio, TX $115,631,179,000 12.79% N/A N/A 16,073 12,380,695
32 Discover Bank Greenwood, DE $108,936,256,000 -2.94% N/A N/A 11,005 6,404,620
33 Bank of the West San Francisco, CA $99,178,981,000 -0.82% 533 19 9,049 1,882,871
34 Signature Bank New York, NY $97,209,737,000 37.92% 36 4 1,795 161,502
35 Santander Bank, N.A Wilmington, DE $95,192,570,000 7.82% 516 9 8,566 3,162,380
36 UBS Bank USA Salt Lake City, UT $94,957,060,000 20.38% 1 0 481 4,191
37 Comerica Bank Dallas, TX $88,331,000,000 4.40% 434 5 6,755 1,102,557
38 First Horizon Bank Memphis, TN $87,574,096,000 44.66% 0 0 7,551 1,718,324
39 Zions Bank Salt Lake City, UT $87,208,406,000 12.34% 419 11 9,727 1,499,774
40 City National Bank (CA) Los Angeles, CA $84,955,426,000 15.87% 75 9 5,369 281,135
41 Synchrony Bank Draper, UT $81,927,000,000 -3.91% N/A N/A 8,810 2,546,222
42 East West Bank Pasadena, CA $59,838,864,000 17.43% 117 7 3,161 567,136
43 New York Community Bank Hicksville, NY $57,444,945,000 5.67% 237 5 2,785 730,987
44 First Citizens Bank (NC) Raleigh, NC $55,098,938,000 13.20% 524 19 6,654 1,688,254
45 Synovus Bank Columbus, GA $54,872,532,000 1.52% 284 5 4,772 813,456
46 State Employees' Credit Union (NC) Raleigh, NC $49,939,131,000 9.51% 277 1 6,886 5,197,698
47 CIT Bank Pasadena, CA $49,309,230,000 -13.10% N/A N/A 3,470 589,713
48 Western Alliance Bank Phoenix, AZ $49,068,916,000 34.93% 36 1 3,205 152,964
49 BOK Financial Tulsa, OK $46,909,545,000 2.74% 0 2 4,573 696,415
50 Frost Bank San Antonio, TX $46,734,243,000 15.61% 162 1 4,528 739,230
51 CIBC Bank USA Chicago, IL $45,147,152,000 14.11% 24 4 1,720 125,252
52 Deutsche Bank Trust Company Americas New York, NY $42,726,000,000 -5.49% 2 1 431 9,903
53 Valley Passaic, NJ $41,294,181,000 -0.99% 213 4 3,130 717,808
54 South State Bank Winter Haven, FL $40,262,683,000 6.31% 285 3 5,203 1,132,018
55 First National Bank of Pennsylvania Pittsburgh, PA $38,437,671,000 1.99% 334 8 3,867 1,102,488
56 TIAA Bank Jacksonville, FL $38,435,437,000 -10.34% N/A N/A 1,826 371,115
57 UMB Bank, National Association Kansas City, MO $36,376,318,000 18.43% 98 8 2,765 1,155,261
58 Prosperity Bank (TX) El Campo, TX $36,098,031,000 8.65% 294 2 3,724 784,990
59 BankUnited Miami Lakes, FL $35,583,698,000 2.72% 70 2 1,425 154,306
60 Texas Capital Bank Dallas, TX $35,217,132,000 -3.66% 10 1 1,557 33,150
61 Pinnacle Bank (TN) Nashville, TN $35,216,904,000 5.74% 54 5 2,706 389,620
62 Pacific Western Bank Beverly Hills, CA $34,820,512,000 21.49% 74 2 2,055 138,707
63 Raymond James Bank Saint Petersburg, FL $34,576,165,000 15.94% 1 1 275 6,006
64 Associated Bank, NA Green Bay, WI $34,102,811,000 -3.81% 231 3 4,007 1,108,550
65 Webster Bank Waterbury, CT $33,737,378,000 3.01% 134 4 2,937 1,276,844
66 Commerce Bank Kansas City, MO $33,712,939,000 9.81% 167 5 4,433 1,061,825
67 MidFirst Bank Oklahoma City, OK $31,048,180,000 21.63% 78 3 2,905 537,495
68 Umpqua Bank Roseburg, OR $30,290,285,000 2.17% 227 5 3,755 749,287
69 Sterling National Bank (NY) Pearl River, NY $29,057,043,000 -5.54% 75 1 1,491 509,524
70 Sallie Mae Bank Salt Lake City, UT $28,835,767,000 -5.20% N/A N/A 1,623 316,959
71 Barclays Wilmington, DE $28,773,000,000 -12.61% N/A N/A 2,825 762,267
72 BECU (Boeing Employees Credit Union) Tukwila, WA $28,643,913,000 13.58% 59 2 2,494 2,856,401
73 PenFed Credit Union McLean, VA $27,652,680,000 6.25% 41 14 3,128 3,225,727
74 Bancorp South Tupelo, MS $27,616,695,000 15.94% 324 9 4,835 764,441
75 United Bank (VA) Fairfax, VA $27,158,306,000 3.49% 205 3 2,944 587,082
76 Flagstar Bank Troy, MI $27,043,034,000 -1.43% 158 5 5,503 520,394
77 Investors Bank Short Hills, NJ $26,765,369,000 -1.49% 147 2 1,688 488,462
78 FirstBank (Lakewood, CO) Lakewood, CO $26,751,618,000 15.89% 109 3 2,554 995,106
79 Bank OZK Little Rock, AR $26,605,938,000 0.85% 234 7 2,588 592,512
80 Arvest Bank Fayetteville, AR $26,237,693,000 11.51% 243 4 6,237 1,582,807
81 Fulton Bank, National Association Lancaster, PA $25,922,789,000 5.52% 203 5 3,192 748,432
82 SchoolsFirst Federal Credit Union Santa Ana, CA $25,874,585,000 16.43% 68 1 2,365 2,831,491
83 First National Bank of Omaha Omaha, NE $25,479,621,000 6.25% 50 4 4,128 937,545
84 First Hawaiian Bank Honolulu, HI $24,246,092,000 5.17% 54 1 2,087 540,513
85 Old National Bank Evansville, IN $23,577,324,000 6.69% 100 5 2,230 717,783
86 Simmons Bank Pine Bluff, AR $23,379,838,000 6.52% 211 6 2,764 602,715
87 Bank of Hawaii Honolulu, HI $22,642,103,000 12.81% 52 1 2,085 622,377
88 Ameris Bank Atlanta, GA $21,791,489,000 9.20% 168 5 2,686 456,304
89 FirstBank (FL) Miami, FL $21,361,138,000 34.07% 84 1 3,172 660,279
90 Pacific Premier Bank Irvine, CA $20,533,652,000 0.09% 41 5 1,521 156,494
91 Glacier Bank Kalispell, MT $20,475,522,000 17.48% 55 1 2,982 709,289
92 City National Bank (FL) Miami, FL $20,235,407,000 13.78% 32 1 910 75,134
93 Atlantic Union Bank Richmond, VA $19,953,865,000 1.24% 129 3 1,885 497,101
94 WaFd Bank Seattle, WA $19,651,718,000 7.49% 220 8 2,058 462,584
95 Customers Bank Phoenixville, PA $19,634,826,000 8.87% 13 3 605 2,379,856
96 Cathay Bank Los Angeles, CA $19,330,759,000 0.49% 59 8 1,173 273,675
97 Wells Fargo National Bank West Las Vegas, NV $19,275,160,000 11.05% 1 1 0 347,668
98 First Interstate Bank Billings, MT $18,879,309,000 13.07% 147 6 2,391 462,898
99 United Community Bank (GA) Blairsville, GA $18,867,020,000 20.62% 148 4 2,434 512,789
100 Mechanics Bank (CA) Walnut Creek, CA $18,797,454,000 -0.38% 124 1 1,827 363,560
CodePudding user response:
your error is coming from the fact you just select one record
if you want a solution nearest to yours:
from selenium.webdriver.support import expected_conditions as EC
:
:
url='https://www.depositaccounts.com/banks/assets.aspx?instType=&stateType=hq&state='
driver.get(url)
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="results"]/div/a'))).click()
time.sleep(3)
records = driver.find_elements(By.XPATH, "//table[@id='assetsTable']//tr[not(./th)]")
nbr_records = len(records)
bank_results = []
for i in range(nbr_records):
temporary_data={
'Rank': records[i].find_element(By.XPATH, "./td[1]").text,
'Financial Institution': records[i].find_element(By.XPATH, "./td[2]").text,
'Headquarters': records[i].find_element(By.XPATH, "./td[3]").text,
'Assets': records[i].find_element(By.XPATH, "./td[4]").text,
'Asset Growth': records[i].find_element(By.XPATH, "./td[5]").text,
'Branches': records[i].find_element(By.XPATH, "./td[6]").text,
'States with Branches': records[i].find_element(By.XPATH, "./td[7]").text,
'Employees': records[i].find_element(By.XPATH, "./td[8]").text,
'Customer Accounts': records[i].find_element(By.XPATH, "./td[9]").text
}
bank_results.append(temporary_data)
xpath = "//table[@id='assetsTable']//tr[not(./th)]"
means
select all trs which dont contain a tag th and have a parent table with id = assetsTable