Files
004_comission/ych1990101/task1-optimized/app/notebook/utils/GetScreenshot.py
louiscklaw cd995ed8bd update,
2025-01-31 20:05:06 +08:00

65 lines
2.0 KiB
Python

#!/usr/bin/env python
from playwright.async_api import async_playwright
def helloworld():
print("helloworld")
async def getScreenshot_bmstatistics(url, file_path, timeout_s):
async with async_playwright() as pw:
browser = await pw.chromium.launch(headless=True)
page = await browser.new_page()
await page.goto(url)
await page.wait_for_timeout(timeout_s * 1000)
# await page.waitForSelector('xpath=//*[contains(text(), "Total Goals")]');
await page.get_by_text("Total Goals").click()
await page.screenshot(path=file_path, full_page=True)
await browser.close()
async def getScreenshot_bmrecentforms(url, file_path, timeout_s):
async with async_playwright() as pw:
browser = await pw.chromium.launch(headless=True)
page = await browser.new_page()
await page.goto(url)
elements = await page.locator('select.select-margin').all()
with open('./result.txt','w') as fo:
fo.write(str(len(elements)))
await elements[0].select_option(label="Home Matches")
await elements[1].select_option(label="Away Matches")
await page.screenshot(path=file_path, full_page=True)
await browser.close()
async def getScreenshot_standings(url, file_path, timeout_s):
async with async_playwright() as pw:
browser = await pw.chromium.launch(headless=True)
page = await browser.new_page()
await page.goto(url)
await page.wait_for_timeout(timeout_s * 1000)
await page.screenshot(path=file_path, full_page=True)
await browser.close()
async def getScreenshot(url, file_path, timeout_s):
async with async_playwright() as pw:
browser = await pw.chromium.launch(headless=True)
page = await browser.new_page()
await page.goto(url)
await page.wait_for_timeout(timeout_s * 1000)
await page.screenshot(path=file_path, full_page=True)
await browser.close()