from playwright.async_api import async_playwright, TimeoutError as PlaywrightTimeoutError from typing import Dict from fastapi import FastAPI, HTTPException from pydantic import BaseModel async def scraper(link: str) -> Dict: async with async_playwright() as p: browser = await p.chromium.launch(headless=True) context = await browser.new_context() page = await context.new_page() try: await page.goto(link, timeout=15000) except PlaywrightTimeoutError: await browser.close() return {"error": "Timeout while loading the page."} # Get body text page_text = await page.locator("body").inner_text() # Get all