Created
February 5, 2019 03:31
-
-
Save zemerick1/00a51945c7ef9d8dce3f37af34f21db4 to your computer and use it in GitHub Desktop.
AMEX - HYSA Scraper #Python #Web #Selenium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup | |
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
import os | |
import sys | |
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'} | |
url = 'https://personalsavings.americanexpress.com/onlinebanking/' | |
chromedriver = 'chromedriver.exe' | |
driver = webdriver.Chrome(chromedriver) | |
driver.minimize_window() | |
driver.get(url) | |
user = sys.argv[1] | |
userpass = sys.argv[2] | |
username = driver.find_element_by_id("userName") | |
password = driver.find_element_by_id("password") | |
username.send_keys(user) | |
password.send_keys(userpass) | |
# Click the login button | |
driver.find_element_by_name('_eventId_submit').click() | |
r_html = driver.page_source | |
driver.close() | |
soup = BeautifulSoup(r_html, 'html.parser') | |
for script in soup(["script", "style"]): | |
script.decompose() # rip it out | |
# How many accounts do we have | |
a_count = len(soup.find_all('div', attrs={'class': 'nickname'})) | |
a_count = a_count - 1 # Account for the fact the tables start counting at 0 | |
# While counter | |
count = 0 | |
# Find the first instance of account name. | |
nickname = soup.find('div', attrs={'class': 'nickname'}) | |
# Return Data dict | |
data = {} | |
while(count <= a_count): | |
# Print first account name | |
name = nickname.getText() | |
# Print the next tag that is td (our account) | |
amount = nickname.find_next('td', attrs = {'class' : 'right', 'style' : 'width: 15%;'}).getText() | |
# Make a pretty string to store | |
#name = name.replace('HYSA - ', '') | |
data[name] = amount | |
# Iterate to the next account name | |
nickname = nickname.find_next('div', attrs={'class': 'nickname'}) | |
# Increase counter to find more accounts. | |
count += 1 | |
print(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment