AkahuSync/emoneyscraper/scraper.py

28 lines
970 B
Python
Raw Normal View History

2026-05-09 04:39:54 +00:00
from playwright.sync_api import sync_playwright, Playwright
import os
from dotenv import load_dotenv
load_dotenv()
2026-05-09 04:39:54 +00:00
def run(playwright: Playwright):
firefox = playwright.firefox # or "firefox" or "webkit".
browser = firefox.launch(headless=False)
2026-05-09 04:39:54 +00:00
page = browser.new_page()
response = page.goto(os.getenv("URL"))
2026-05-09 06:55:48 +00:00
page.fill("input#ctl00_ContentPlaceHolder1_txtLoginID", os.getenv("USERNAME"))
page.fill("input#ctl00_ContentPlaceHolder1_txtPassword", os.getenv("PASSWORD"))
page.click("input#ctl00_ContentPlaceHolder1_btnLogin")
html_content = page.content()
with open('result.html', 'w', encoding='utf-8') as f:
f.write(html_content)
current_balance = page.locator("xpath=/html/body/form/div[3]/div[3]/div[2]/div[3]/div[5]/span[2]").inner_text()
print(current_balance)
2026-05-09 04:39:54 +00:00
browser.close()
#xpath = /html/body/form/div[3]/div[3]/div[2]/div[3]/div[5]/span[2]
2026-05-09 04:39:54 +00:00
with sync_playwright() as playwright:
run(playwright)