z230
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
from playwright.sync_api import sync_playwright
|
||||
from datetime import datetime
|
||||
import os
|
||||
|
||||
EMAIL = "vbuzalka@its.jnj.com"
|
||||
PASSWORD = "%zT3Wqfc9)cWua5"
|
||||
LOGIN_URL = "https://xsp.covance.com/"
|
||||
REPORT_URL = (
|
||||
"https://xsp.labcorp.com/sponsor/study/36940/kit-inventory/on-hand-expiration"
|
||||
"?site=%5B%22CZ10001-213069%22,%22CZ10010-213069%22,%22CZ10022-213069%22,"
|
||||
"%22CZ10020-213069%22,%22CZ10012-213069%22,%22CZ10021-213069%22,"
|
||||
"%22CZ10016-213069%22,%22CZ10003-213069%22,%22CZ10009-213069%22,"
|
||||
"%22CZ10015-213069%22,%22CZ10013-213069%22,%22CZ10006-213069%22%5D"
|
||||
"&recordLimit=true"
|
||||
)
|
||||
OUT_DIR = r"U:\PythonProject\Janssen\Covance_UCO3001\Source"
|
||||
PROFILE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "browser_profile")
|
||||
|
||||
|
||||
def login(page):
|
||||
page.goto(LOGIN_URL)
|
||||
page.wait_for_load_state("networkidle")
|
||||
page.get_by_label("Email").fill(EMAIL)
|
||||
page.get_by_role("button", name="Next").click()
|
||||
page.wait_for_load_state("networkidle")
|
||||
page.get_by_label("Password").fill(PASSWORD)
|
||||
page.get_by_role("button", name="Verify").click()
|
||||
page.wait_for_url(lambda url: "code=" not in url, timeout=60000)
|
||||
page.wait_for_load_state("networkidle", timeout=60000)
|
||||
page.wait_for_timeout(2000)
|
||||
print(f"Prihlaseni OK: {page.url}")
|
||||
|
||||
|
||||
def download(page):
|
||||
page.goto(REPORT_URL)
|
||||
page.wait_for_load_state("networkidle", timeout=60000)
|
||||
print(f"Report nacteny: {page.url}")
|
||||
|
||||
page.locator("ag-export").get_by_role("button", name="more_horiz").click()
|
||||
with page.expect_download(timeout=60000) as dl:
|
||||
page.get_by_text("Export to CSV").click()
|
||||
|
||||
timestamp = datetime.now().strftime("%Y-%m-%d_%H%M%S")
|
||||
dest = os.path.join(OUT_DIR, f"{timestamp} sponsor-study-36940-kit-inventory-on-hand-expiration.csv")
|
||||
dl.value.save_as(dest)
|
||||
print(f"Stazeno: {dest}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with sync_playwright() as p:
|
||||
context = p.chromium.launch_persistent_context(
|
||||
user_data_dir=PROFILE_DIR,
|
||||
headless=False,
|
||||
args=["--disable-blink-features=AutomationControlled"],
|
||||
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36",
|
||||
accept_downloads=True,
|
||||
)
|
||||
context.add_init_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
|
||||
page = context.new_page()
|
||||
login(page)
|
||||
download(page)
|
||||
context.close()
|
||||
Reference in New Issue
Block a user