Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,24 @@
|
|
1 |
from fastapi import FastAPI
|
2 |
-
import
|
|
|
3 |
|
4 |
app = FastAPI()
|
5 |
-
|
6 |
@app.get("/fetch")
|
7 |
def fetch_html(url: str):
|
8 |
try:
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
except requests.RequestException as e:
|
18 |
return {"error": str(e)}
|
19 |
|
|
|
20 |
if __name__ == "__main__":
|
21 |
import uvicorn
|
|
|
22 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
1 |
from fastapi import FastAPI
|
2 |
+
from playwright.sync_api import sync_playwright
|
3 |
+
import os
|
4 |
|
5 |
app = FastAPI()
|
6 |
+
|
7 |
@app.get("/fetch")
|
8 |
def fetch_html(url: str):
|
9 |
try:
|
10 |
+
with sync_playwright() as p:
|
11 |
+
browser = p.chromium.launch(headless=True)
|
12 |
+
page = browser.new_page()
|
13 |
+
page.goto(url, timeout=15000)
|
14 |
+
html = page.content()
|
15 |
+
browser.close()
|
16 |
+
return {"html": html}
|
17 |
+
except Exception as e:
|
|
|
18 |
return {"error": str(e)}
|
19 |
|
20 |
+
|
21 |
if __name__ == "__main__":
|
22 |
import uvicorn
|
23 |
+
os.system("playwright install chromium")
|
24 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|