0

Update main.py

This commit is contained in:
Nicolas 2024-05-09 18:00:58 -07:00
parent 08d6c59a78
commit 73687822ad

View File

@ -8,6 +8,7 @@ app = FastAPI()
class UrlModel(BaseModel):
url: str
wait: int = None
browser: Browser = None
@ -29,7 +30,9 @@ async def shutdown_event():
async def root(body: UrlModel):
context = await browser.new_context()
page = await context.new_page()
await page.goto(body.url)
await page.goto(body.url, timeout=15000) # Set max timeout to 15s
if body.wait: # Check if wait parameter is provided in the request body
await page.wait_for_timeout(body.wait) # Convert seconds to milliseconds for playwright
page_content = await page.content()
await context.close()
json_compatible_item_data = {"content": page_content}