Base on asyncio、 aiohttp、 sanic
Build web service base on sanic.
Proxies will be stored in Redis, a memory-based database that is fast.
git clone https://github.com/zmingGit/ProxyIP
pip install -r requirements.txt
You can find the config.py
file in the ProxyIP folder. You can run the service after updating the redis connection config.
# run spider
python client.py
# run web service
python server.py
This project can be divided into several modules.
crawler
: fetch proxies, test proxies, stored to redis.
store
: encapsulate the redis interface, provide connection pool.
validtor
: verify proxies in redis, remove them if necessary.
scheduler
: registration time, will dispatch crawler and validtor.
webapi
: provide web service.
import random
import requests
# make sure the web service is started
try:
proxies = requests.get("http://localhost:3289/get/20").json()
req = requests.get("https://example.com", proxies=random.choice(proxies))
except:
raise
# or
try:
proxy = requests.get("http://localhost:3289/pop").json()
req = requests.get("https://example.com", proxies=proxy)
except:
raise
MIT ©zming