Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import pprint
- import re
- from string import ascii_letters
- from bs4 import BeautifulSoup as bs4
- pp = pprint.PrettyPrinter(indent=4).pprint
- username = r'xxxxxxxxxxx'
- password = r'xxxxxxxxx'
- account_id = 'xxxxxxxxxxxxxxxxxx'
- logon_url = 'https://c2g.toaks.org/Click2GovCX/logonuser.html'
- def get_csrf(text):
- soup = bs4(text, 'html.parser')
- csrf_token = soup.find('input', {'name': 'OWASP_CSRFTOKEN'})['value']
- return csrf_token
- def login(s, r):
- csrf_token = get_csrf(r.text)
- payload = {
- 'email.emailId': username,
- 'onsubmitLogonUser': 'Logon',
- 'pageUsedCode': 'userAuthLogonUser',
- 'OWASP_CSRFTOKEN': csrf_token,
- 'password': password
- }
- r = s.post(logon_url, data=payload)
- return r
- def account_url(text):
- soup = bs4(text, 'html.parser')
- account_url = base_url + (soup.find('a', {'title': 'Account Information'})['href'])
- return account_url
- def get_balance(r):
- soup = bs4(r.text, 'html.parser')
- rows = soup.find_all('div', {'class': 'form-group dataRow'})
- for row in rows:
- m = re.search('Account Balance', row.text)
- if m:
- for i in row.find_all('span'):
- balance = row.find('span', {'class': 'col-xs-12 col-sm-7 col-md-9 form-control-static'}).text
- if balance is None:
- # Nick is trying to fuck with me.
- balance = ''
- for i in row.find_all('span'):
- balance = balance + i.text
- balance = balance_strip(balance)
- return balance
- def balance_strip(text):
- arr = (
- '$',
- '\r',
- '\n',
- '*',
- ' '
- )
- for a in arr:
- text = text.replace(a, '')
- return text
- def balance():
- with requests.Session() as s:
- r = s.get(logon_url)
- r = login(s, r)
- url = account_url(r.text)
- r = s.get(url)
- b = get_balance(r)
- return b
- if __name__ == '__main__':
- balance()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement