from playwright.sync_api import sync_playwright, Playwright import os from dotenv import load_dotenv load_dotenv() class Scraper: def __init__(self, playwright: Playwright, headless: bool = True): self.playwright = playwright self.firefox = self.playwright.firefox # or "firefox" or "webkit". self.browser = self.firefox.launch(headless=headless) self.page = self.browser.new_page() self.response = self.page.goto(os.getenv("URL")) self.page.fill("input#ctl00_ContentPlaceHolder1_txtLoginID", os.getenv("USERNAME")) self.page.fill("input#ctl00_ContentPlaceHolder1_txtPassword", os.getenv("PASSWORD")) self.page.click("input#ctl00_ContentPlaceHolder1_btnLogin") def get_balance(self): current_balance = self.page.locator("xpath=/html/body/form/div[3]/div[3]/div[2]/div[3]/div[5]/span[2]").inner_text() return current_balance def get_transactions(self): self.page.click("xpath=/html/body/form/div[3]/div[3]/div[2]/div[3]/div[1]/span[2]/a") transaction_body = self.page.locator("xpath=/html/body/form/div[3]/div[3]/div[2]/div/div[2]/div[3]/table/tbody").inner_text() return transaction_body def close(self): self.browser.close() #xpathbody=/html/body/form/div[3]/div[3]/div[2]/div/div[2]/div[3]/table/tbody #xpathaccountbutton = /html/body/form/div[3]/div[3]/div[2]/div[3]/div[1]/span[2]/a #xpath = /html/body/form/div[3]/div[3]/div[2]/div[3]/div[5]/span[2]