Update main.py
This commit is contained in:
parent
08d6c59a78
commit
73687822ad
@ -8,6 +8,7 @@ app = FastAPI()
|
|||||||
|
|
||||||
class UrlModel(BaseModel):
|
class UrlModel(BaseModel):
|
||||||
url: str
|
url: str
|
||||||
|
wait: int = None
|
||||||
|
|
||||||
|
|
||||||
browser: Browser = None
|
browser: Browser = None
|
||||||
@ -29,7 +30,9 @@ async def shutdown_event():
|
|||||||
async def root(body: UrlModel):
|
async def root(body: UrlModel):
|
||||||
context = await browser.new_context()
|
context = await browser.new_context()
|
||||||
page = await context.new_page()
|
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()
|
page_content = await page.content()
|
||||||
await context.close()
|
await context.close()
|
||||||
json_compatible_item_data = {"content": page_content}
|
json_compatible_item_data = {"content": page_content}
|
||||||
|
Loading…
Reference in New Issue
Block a user