mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
POC: download file from ecmk using playwright
This commit is contained in:
parent
e5bc9e3ecb
commit
1fee40bfef
1 changed files with 72 additions and 0 deletions
72
scripts/download_ecmk_files.py
Normal file
72
scripts/download_ecmk_files.py
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
import os
|
||||
from playwright.sync_api import sync_playwright, TimeoutError as PlaywrightTimeoutError
|
||||
|
||||
|
||||
def download_report(username: str, password: str):
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=True)
|
||||
|
||||
context = browser.new_context()
|
||||
page = context.new_page()
|
||||
|
||||
try:
|
||||
# 1. Go to site
|
||||
page.goto("https://assessorhub.net/", timeout=30000)
|
||||
|
||||
# 2. Login (UPDATE selectors if needed)
|
||||
username_input = page.locator("#Username")
|
||||
password_input = page.locator("#Password")
|
||||
|
||||
username_input.wait_for(state="visible", timeout=10000)
|
||||
username_input.fill(username)
|
||||
|
||||
password_input.wait_for(state="visible", timeout=10000)
|
||||
password_input.fill(password)
|
||||
|
||||
# 3. Submit login
|
||||
with page.expect_navigation(timeout=15000):
|
||||
page.click("button[type='submit']")
|
||||
|
||||
# 4. Verify login succeeded
|
||||
if "login" in page.url.lower():
|
||||
raise Exception("Login failed")
|
||||
|
||||
print("Login successful:", page.url)
|
||||
|
||||
# 5. Navigate to the assessment detail page
|
||||
page.goto(
|
||||
"https://assessorhub.net/Assessments/Assessments/Detail/1bd9fd74-08f6-4fc1-b2f7-3a13a8f9084d?returnUrl=/Companies/Assessments",
|
||||
timeout=30000,
|
||||
)
|
||||
|
||||
# 6. Locate the correct download button
|
||||
button = page.locator("a.download-report-btn[data-report-type='11']")
|
||||
|
||||
button.wait_for(state="visible", timeout=10000)
|
||||
|
||||
# 7. Click and capture the download
|
||||
with page.expect_download(timeout=30000) as download_info:
|
||||
button.click()
|
||||
|
||||
download = download_info.value
|
||||
|
||||
# 8. Save file locally
|
||||
filename = download.suggested_filename
|
||||
save_path = os.path.join(os.getcwd(), filename)
|
||||
|
||||
download.save_as(save_path)
|
||||
|
||||
print(f"Downloaded file saved to: {save_path}")
|
||||
|
||||
except PlaywrightTimeoutError as e:
|
||||
raise Exception(f"Timeout occurred: {str(e)}")
|
||||
|
||||
finally:
|
||||
context.close()
|
||||
browser.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
email = ""
|
||||
password = ""
|
||||
download_report(email, password)
|
||||
Loading…
Add table
Reference in a new issue