Spaces:
Running
Running
File size: 718 Bytes
a3bb0bd b5b2e6a a3bb0bd 1d78f18 b5b2e6a a3bb0bd ea680b0 a3bb0bd ea680b0 a3bb0bd b5b2e6a a3bb0bd dbf8d54 949bf2b c8510e0 676b3da c8510e0 1a44639 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
import hrequests
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI()
class URLRequest(BaseModel):
url: str
@app.post("/scrape")
async def scrape(url_request: URLRequest):
try:
response = hrequests.get(url_request.url)
return {"content": response.text}
except Exception as e:
raise e
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/", tags=["Home"])
def api_home():
return {'detail': 'Welcome to Web-Scraping API! Visit https://pvanand-web-scraping.hf.space/docs to test'} |