fix Screenshotter
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from beaky.config import Config
|
||||
@@ -10,17 +11,40 @@ class Screenshotter:
|
||||
|
||||
|
||||
def capture_tickets(self, links: list[Link]):
|
||||
for link in links:
|
||||
print("capturing link:", link)
|
||||
target_path = Path(self.config.screenshotter.target_path) / f"{link.id}.png"
|
||||
self.capture_ticket(link.url, target_path)
|
||||
|
||||
def capture_ticket(self, url, target_path, ticket_selector=".betslip-history-detail"):
|
||||
with sync_playwright() as p:
|
||||
browser = p.chromium.launch(headless=True)
|
||||
page = browser.new_page()
|
||||
page.goto(url, wait_until="domcontentloaded")
|
||||
page.wait_for_selector(ticket_selector)
|
||||
page.wait_for_load_state("networkidle")
|
||||
page.locator(ticket_selector).screenshot(path=target_path)
|
||||
context = browser.new_context()
|
||||
|
||||
for link in links:
|
||||
print("capturing link:", link)
|
||||
page = context.new_page()
|
||||
target_path = Path(self.config.screenshotter.target_path) / f"{link.id}.png"
|
||||
self.capture_ticket(page, link.url, target_path)
|
||||
|
||||
browser.close()
|
||||
|
||||
def capture_ticket(self,page, url, target_path, ticket_selector=".betslip-history-detail__left-panel"):
|
||||
page.goto(url)
|
||||
page.wait_for_selector(ticket_selector, timeout=10000)
|
||||
page.wait_for_timeout(1000)
|
||||
page.evaluate(f"""
|
||||
let el = document.querySelector('{ticket_selector}');
|
||||
if (el) {{
|
||||
// Roztáhneme samotný kontejner se zápasy
|
||||
let wrapper = el.querySelector('.betslip-selections');
|
||||
if (wrapper) {{
|
||||
wrapper.style.setProperty('height', 'auto', 'important');
|
||||
wrapper.style.setProperty('overflow', 'visible', 'important');
|
||||
}}
|
||||
|
||||
// A teď projdeme všechny nadřazené prvky až k <body>
|
||||
while (el && el !== document.body) {{
|
||||
el.style.setProperty('height', 'auto', 'important');
|
||||
el.style.setProperty('max-height', 'none', 'important');
|
||||
el.style.setProperty('overflow', 'visible', 'important');
|
||||
el = el.parentElement;
|
||||
}}
|
||||
}}
|
||||
""")
|
||||
|
||||
page.locator(ticket_selector).screenshot(path=target_path)
|
||||
|
||||
Reference in New Issue
Block a user