Spaces:
No application file
No application file
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Request
|
| 2 |
+
import httpx
|
| 3 |
+
from fastapi.responses import HTMLResponse
|
| 4 |
+
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
|
| 7 |
+
@app.get("/proxy", response_class=HTMLResponse)
|
| 8 |
+
async def proxy(request: Request):
|
| 9 |
+
query = request.query_params.get("q")
|
| 10 |
+
if not query:
|
| 11 |
+
return "Please provide a query parameter `q`."
|
| 12 |
+
headers = {"User-Agent": "Mozilla/5.0"}
|
| 13 |
+
async with httpx.AsyncClient() as client:
|
| 14 |
+
response = await client.get(f"https://www.google.com/search?q={query}", headers=headers)
|
| 15 |
+
return response.text
|