Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
import os
|
2 |
import re
|
3 |
from dotenv import load_dotenv
|
4 |
-
from fastapi import FastAPI, HTTPException, Request, Depends, Security
|
5 |
-
from fastapi.responses import StreamingResponse, HTMLResponse, JSONResponse, FileResponse
|
6 |
from fastapi.security import APIKeyHeader
|
7 |
from pydantic import BaseModel
|
8 |
import httpx
|
@@ -401,6 +401,24 @@ async def dynamic_ai_page(request: Request):
|
|
401 |
html_content = ' '.join(html_content.split(' ')[1:])
|
402 |
|
403 |
return HTMLResponse(content=html_content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
404 |
|
405 |
@app.get("/playground", response_class=HTMLResponse)
|
406 |
async def playground():
|
|
|
1 |
import os
|
2 |
import re
|
3 |
from dotenv import load_dotenv
|
4 |
+
from fastapi import FastAPI, HTTPException, Request, Depends, Security, Query
|
5 |
+
from fastapi.responses import StreamingResponse, HTMLResponse, JSONResponse, FileResponse, PlainTextResponse
|
6 |
from fastapi.security import APIKeyHeader
|
7 |
from pydantic import BaseModel
|
8 |
import httpx
|
|
|
401 |
html_content = ' '.join(html_content.split(' ')[1:])
|
402 |
|
403 |
return HTMLResponse(content=html_content)
|
404 |
+
|
405 |
+
|
406 |
+
######################################
|
407 |
+
|
408 |
+
@app.get("/scraper", response_class=PlainTextResponse)
|
409 |
+
def scrape_site(url: str = Query(..., description="URL to scrape")):
|
410 |
+
try:
|
411 |
+
# Try cloudscraper first
|
412 |
+
scraper = cloudscraper.create_scraper()
|
413 |
+
response = scraper.get(url)
|
414 |
+
if response.status_code == 200 and len(response.text.strip()) > 0:
|
415 |
+
return response.text
|
416 |
+
except Exception as e:
|
417 |
+
print(f"Cloudscraper failed: {e}")
|
418 |
+
return "Cloudscraper failed."
|
419 |
+
|
420 |
+
|
421 |
+
#######################################
|
422 |
|
423 |
@app.get("/playground", response_class=HTMLResponse)
|
424 |
async def playground():
|