site-get / app.py
Arkm20's picture
Update app.py
cbee623 verified
raw
history blame
585 Bytes
from fastapi import FastAPI
import requests
app = FastAPI()
@app.get("/fetch")
def fetch_html(url: str):
try:
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
}
response = requests.get(url, headers=headers)
response.raise_for_status()
return {"html": response.text}
except requests.RequestException as e:
return {"error": str(e)}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=7860)