|
from fastapi import FastAPI, HTTPException |
|
from fastapi.middleware.cors import CORSMiddleware |
|
from scraper import Scraper |
|
|
|
|
|
try: from pip._internal.operations import freeze |
|
except ImportError: |
|
from pip.operations import freeze |
|
|
|
pkgs = freeze.freeze() |
|
for pkg in pkgs: print(pkg) |
|
|
|
app = FastAPI() |
|
app.add_middleware( |
|
CORSMiddleware, |
|
allow_origins=["*"], |
|
allow_credentials=True, |
|
allow_methods=["*"], |
|
allow_headers=["*"], |
|
) |
|
import time |
|
|
|
@app.get("/get_scraped_data") |
|
async def get_data(url: str): |
|
|
|
start_time = time.time() |
|
|
|
data = await Scraper.scrape(url) |
|
|
|
end_time = time.time() |
|
|
|
|
|
elapsed_time = end_time - start_time |
|
|
|
print(f"Time taken for the process: {elapsed_time:.2f} seconds") |
|
return data |
|
|
|
|
|
|
|
|