2026-05-09 04:39:54 +00:00
|
|
|
from playwright.sync_api import sync_playwright, Playwright
|
2026-05-09 05:24:37 +00:00
|
|
|
import os
|
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
|
|
|
|
|
|
load_dotenv()
|
2026-05-13 04:31:12 +00:00
|
|
|
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")
|
2026-05-09 04:39:54 +00:00
|
|
|
|
2026-05-13 04:31:12 +00:00
|
|
|
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
|
2026-05-09 04:39:54 +00:00
|
|
|
|
2026-05-13 04:31:12 +00:00
|
|
|
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
|
2026-05-13 04:01:14 +00:00
|
|
|
|
2026-05-13 04:31:12 +00:00
|
|
|
def close(self):
|
|
|
|
|
self.browser.close()
|
2026-05-13 04:01:14 +00:00
|
|
|
|
2026-05-13 04:31:12 +00:00
|
|
|
#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
|
2026-05-13 04:01:14 +00:00
|
|
|
#xpath = /html/body/form/div[3]/div[3]/div[2]/div[3]/div[5]/span[2]
|
|
|
|
|
|