Skip to content

Instantly share code, notes, and snippets.

@itssoap
Created November 2, 2022 19:35
Show Gist options
  • Save itssoap/909f5f3203737df72603ff069ba309f1 to your computer and use it in GitHub Desktop.
Save itssoap/909f5f3203737df72603ff069ba309f1 to your computer and use it in GitHub Desktop.
from fastapi import FastAPI
import httpx
from pycountry import countries
from random import randrange
app = FastAPI()
@app.get("/")
async def getter() -> str:
headers = {
'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.9',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'Pragma': 'no-cache',
'Referer': 'https://geonode.com/free-proxy-list/',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36',
'X-Requested-With': 'XMLHttpRequest',
}
while(True):
country = list(countries)[randrange(249)].alpha_2
try:
resp = httpx.get(f"https://proxylist.geonode.com/api/proxy-list?limit=500&page=1&sort_by=lastChecked&sort_type=desc&country={country}&protocols=http", headers=headers)
proxy_list = resp.json()['data']
which = randrange(len(proxy_list))
proxy = proxy_list[which]["ip"] + ":" + proxy_list[which]["port"]
break
except Exception:
pass
return proxy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment