28 lines
970 B
Python
Executable file
28 lines
970 B
Python
Executable file
from playwright.sync_api import sync_playwright, Playwright
|
|
import os
|
|
from dotenv import load_dotenv
|
|
|
|
|
|
load_dotenv()
|
|
|
|
def run(playwright: Playwright):
|
|
firefox = playwright.firefox # or "firefox" or "webkit".
|
|
browser = firefox.launch(headless=False)
|
|
page = browser.new_page()
|
|
response = page.goto(os.getenv("URL"))
|
|
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)
|
|
browser.close()
|
|
|
|
|
|
|
|
#xpath = /html/body/form/div[3]/div[3]/div[2]/div[3]/div[5]/span[2]
|
|
|
|
with sync_playwright() as playwright:
|
|
run(playwright) |