|
| 1 | +from playwright.sync_api import sync_playwright |
| 2 | +from playwright_stealth import stealth_sync |
| 3 | +import os |
| 4 | +from dotenv import load_dotenv |
| 5 | +load_dotenv() |
| 6 | + |
| 7 | +ua = ( |
| 8 | + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " |
| 9 | + "AppleWebKit/537.36 (KHTML, like Gecko) " |
| 10 | + "Chrome/69.0.3497.100 Safari/537.36" |
| 11 | + ) |
| 12 | + |
| 13 | +test_url = "https://replit.com/@pythondojoarchi/SlipperyGargantuanDebuggers" |
| 14 | + |
| 15 | +with sync_playwright() as p: |
| 16 | + # browser = p.chromium.launch(headless=False |
| 17 | + # , slow_mo=50 |
| 18 | + # ) |
| 19 | + browser = p.chromium.launch() |
| 20 | + context = browser.new_context(user_agent=ua) |
| 21 | + page = context.new_page() |
| 22 | + stealth_sync(page) |
| 23 | + page.goto(os.environ['LOGINURL'], wait_until="domcontentloaded") |
| 24 | + page.screenshot(path="./screen-shots/replit.png") |
| 25 | + |
| 26 | + # Login |
| 27 | + page.locator("xpath=/html/body/div[1]/div/div[2]/div/main/div[2]/div/form/div[1]/input").fill(os.environ['EMAIL']) |
| 28 | + page.locator("xpath=/html/body/div[1]/div/div[2]/div/main/div[2]/div/form/div[2]/div/input").fill(os.environ['PASSWORD']) |
| 29 | + page.locator("xpath=/html/body/div[1]/div/div[2]/div/main/div[2]/div/form/div[3]/button").click() |
| 30 | + page.wait_for_url("https://replit.com/~") |
| 31 | + page.screenshot(path="./screen-shots/replit_after_login.png") |
| 32 | + |
| 33 | + # Download repo files as zip |
| 34 | + page.goto(test_url, wait_until="domcontentloaded") |
| 35 | + page.locator("xpath=/html/body/div[1]/div[1]/div[1]/div[2]/div/div[1]/div/div[3]/div/div[1]/button/div/span").wait_for() |
| 36 | + while page.locator("xpath=/html/body/div[1]/div[1]/div[1]/div[2]/header/div[2]/button").text_content() != "Run": |
| 37 | + print(page.locator("xpath=/html/body/div[1]/div[1]/div[1]/div[2]/header/div[2]/button").text_content()) |
| 38 | + page.wait_for_timeout(2000) |
| 39 | + page.screenshot(path="./screen-shots/target_page.png") |
| 40 | + |
| 41 | + page.locator("xpath=/html/body/div[1]/div[1]/div[1]/div[2]/div/div[1]/div/div[2]/div[1]/div[1]/div/div[3]/button").click() |
| 42 | + with page.expect_download() as download_info: |
| 43 | + page.locator("xpath=/html/body/div[@class='css-1o92kwk']//div[@id='item-4']//div[@class='css-1l2rn59']").click() |
| 44 | + download = download_info.value |
| 45 | + download.save_as(f"./screen-shots/{download.suggested_filename}") |
| 46 | + |
| 47 | + # Clean-up |
| 48 | + context.close() |
| 49 | + browser.close() |
| 50 | + |
| 51 | + |
| 52 | + |
0 commit comments