Last active
April 23, 2021 07:33
-
-
Save alyssadev/53c73e13e3c0b4e8c452eef8528c36d9 to your computer and use it in GitHub Desktop.
A script to download afterpay payment due information and save to afterpay-due.json
This file contains hidden or 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 selenium import webdriver | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support import expected_conditions as EC | |
from subprocess import Popen, PIPE | |
from os import environ | |
try: | |
driver = webdriver.Chrome(environ.get("CHROMEDRIVER_PATH", "chromedriver.exe")) | |
driver.get("https://portal.afterpay.com/au/login-email") | |
_wait = WebDriverWait(driver, 10) | |
wait = lambda selector: _wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, selector))) | |
# Session init | |
wait("input[automation_id='input-email']").send_keys(environ["AFTERPAY_EMAIL"]) | |
driver.find_elements_by_css_selector("button[automation_id='button-submit']")[0].click() | |
wait("input[automation_id='input-password']").send_keys(environ["AFTERPAY_PASSWORD"]) | |
driver.find_elements_by_class_name("checkbox__tick")[0].click() | |
driver.find_elements_by_css_selector("button[automation_id='button-submit']")[0].click() | |
wait(".orders-banner__panel") | |
# Data fetch | |
driver.get("https://portalapi.afterpay.com/portal/consumers/paymentschedule/due?ascending=true&limit=100&offset=0&orderBy=dueDate") | |
with open("afterpay-due.json", "w") as f: | |
f.write(driver.find_element_by_tag_name('pre').text) | |
finally: | |
driver.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment