Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from import Select
code = input("What's the code?")
fp = webdriver.FirefoxProfile()
fp.set_preference("", os.getcwd())
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/excel type")
browser = webdriver.Firefox(firefox_profile=fp)
assert 'HSBC' in browser.title
usernamelm = browser.find_element_by_id('userid1')
usernamelm.send_keys(os.getenv('username') + Keys.RETURN)
browser.implicitly_wait(10) # seconds
memorableAnswerelm = browser.find_element_by_id('memorableAnswer')
securitycodeelm = browser.find_element_by_id('idv_OtpCredential')
securitycodeelm.send_keys(str(code) + Keys.RETURN)
# Perform login
submitelm = browser.find_element_by_css_selector('.csButton.hsbcBibButtonStyle01.csAct')
# Load dashboard
goelm = browser.find_element_by_css_selector('.jhxCursorHand')
# Load statements (choose acount) selection
statementsPageUrl = ""
# Select statements download page
downloadelm = browser.find_element_by_css_selector('.button.act.BIBHSSubmitLink3.BIBHistStmts-no-js-show')
statementLinks = browser.find_elements_by_css_selector('.button.act.BIBHSSubmitLink.BIBHistStmts-no-js-show')
numStatements = len(statementLinks)
# Loop each statement link and download it as an excel sheet
for index, statement in enumerate(statementLinks):
browser.implicitly_wait(10) # seconds
# Regenerate statement link elements as they're stale from visiting other pages
statementLinksFresh = browser.find_elements_by_css_selector('.button.act.BIBHSSubmitLink.BIBHistStmts-no-js-show')
# Click individual statement link
# Perform download of excel sheet
transactiondownloadradioelm = browser.find_element_by_id('txdownload')
formatselectionelm = browser.find_element_by_id('formats')
# Choose excel file format
# Initial Download button (there is a confirmation step)
downloadelm = browser.find_elements_by_css_selector('.hsbcBibButtonStyle01B2GUpdate.BIBHistStmts-no-js-show')[3]
if 'Download' not in downloadelm.get_attribute('value'):
#Subsequent pages have different class names, which throw out download btn index
downloadelm = browser.find_elements_by_css_selector('.hsbcBibButtonStyle01B2GUpdate.BIBHistStmts-no-js-show')[5]
# Download confirm button
downloadconfirmelm = browser.find_element_by_css_selector('.hsbcBibButtonStyle01B2G') # Perform excel download
# Go back to statements page
# Select statements download page
downloadelm = browser.find_element_by_css_selector('.button.act.BIBHSSubmitLink3.BIBHistStmts-no-js-show')

This comment has been minimized.

Copy link
Owner Author

@chrisjsimpson chrisjsimpson commented Jul 23, 2018


Run it


It will ask for a code, this is the code the smart card reader HSBC bank users
use to login to their online bank, with their pin number; it generates a
time-bound login key.

You'll note the memorableAnswerelm is empty, and usually the password (fetch
this from somehwere , don't hardcode it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment