File size: 521 Bytes
c5e7785
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from fastapi import FastAPI, Request
import httpx
from fastapi.responses import HTMLResponse

app = FastAPI()

@app.get("/proxy", response_class=HTMLResponse)
async def proxy(request: Request):
    query = request.query_params.get("q")
    if not query:
        return "Please provide a query parameter `q`."
    headers = {"User-Agent": "Mozilla/5.0"}
    async with httpx.AsyncClient() as client:
        response = await client.get(f"https://www.google.com/search?q={query}", headers=headers)
    return response.text