afterpay-fetch-data.py
· 1.3 KiB · Python
Raw
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()
| 1 | from selenium import webdriver |
| 2 | from selenium.webdriver.common.by import By |
| 3 | from selenium.webdriver.support.ui import WebDriverWait |
| 4 | from selenium.webdriver.support import expected_conditions as EC |
| 5 | from subprocess import Popen, PIPE |
| 6 | from os import environ |
| 7 | |
| 8 | try: |
| 9 | driver = webdriver.Chrome(environ.get("CHROMEDRIVER_PATH", "chromedriver.exe")) |
| 10 | driver.get("https://portal.afterpay.com/au/login-email") |
| 11 | _wait = WebDriverWait(driver, 10) |
| 12 | wait = lambda selector: _wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, selector))) |
| 13 | |
| 14 | # Session init |
| 15 | wait("input[automation_id='input-email']").send_keys(environ["AFTERPAY_EMAIL"]) |
| 16 | driver.find_elements_by_css_selector("button[automation_id='button-submit']")[0].click() |
| 17 | |
| 18 | wait("input[automation_id='input-password']").send_keys(environ["AFTERPAY_PASSWORD"]) |
| 19 | driver.find_elements_by_class_name("checkbox__tick")[0].click() |
| 20 | driver.find_elements_by_css_selector("button[automation_id='button-submit']")[0].click() |
| 21 | wait(".orders-banner__panel") |
| 22 | |
| 23 | # Data fetch |
| 24 | driver.get("https://portalapi.afterpay.com/portal/consumers/paymentschedule/due?ascending=true&limit=100&offset=0&orderBy=dueDate") |
| 25 | |
| 26 | with open("afterpay-due.json", "w") as f: |
| 27 | f.write(driver.find_element_by_tag_name('pre').text) |
| 28 | finally: |
| 29 | driver.quit() |