| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- .. ProxyPool documentation master file, created by
- sphinx-quickstart on Wed Jul 8 16:13:42 2020.
- You can adapt this file completely to your liking, but it should at least
- contain the root `toctree` directive.
- ProxyPool
- =====================================
- ::
- ****************************************************************
- *** ______ ********************* ______ *********** _ ********
- *** | ___ \_ ******************** | ___ \ ********* | | ********
- *** | |_/ / \__ __ __ _ __ _ | |_/ /___ * ___ | | ********
- *** | __/| _// _ \ \ \/ /| | | || __// _ \ / _ \ | | ********
- *** | | | | | (_) | > < \ |_| || | | (_) | (_) || |___ ****
- *** \_| |_| \___/ /_/\_\ \__ |\_| \___/ \___/ \_____/ ****
- **** __ / / *****
- ************************* /___ / *******************************
- ************************* ********************************
- ****************************************************************
- Python爬虫代理IP池
- 安装
- -----
- * 下载代码
- .. code-block:: console
- $ git clone git@github.com:jhao104/proxy_pool.git
- * 安装依赖
- .. code-block:: console
- $ pip install -r requirements.txt
- * 更新配置
- .. code-block:: python
- HOST = "0.0.0.0"
- PORT = 5000
- DB_CONN = 'redis://@127.0.0.1:8888'
- PROXY_FETCHER = [
- "freeProxy01",
- "freeProxy02",
- # ....
- ]
- * 启动项目
- .. code-block:: console
- $ python proxyPool.py schedule
- $ python proxyPool.py server
- 使用
- ______
- * API
- ============ ======== ================ ==============
- Api Method Description Arg
- ============ ======== ================ ==============
- / GET API介绍 无
- /get GET 随机返回一个代理 无
- /get_all GET 返回所有代理 无
- /get_status GET 返回代理数量 无
- /delete GET 删除指定代理 proxy=host:ip
- ============ ======== ================ ==============
- * 爬虫
- .. code-block:: python
- import requests
- def get_proxy():
- return requests.get("http://127.0.0.1:5010/get/").json()
- def delete_proxy(proxy):
- requests.get("http://127.0.0.1:5010/delete/?proxy={}".format(proxy))
- # your spider code
- def getHtml():
- # ....
- retry_count = 5
- proxy = get_proxy().get("proxy")
- while retry_count > 0:
- try:
- html = requests.get('http://www.example.com', proxies={"http": "http://{}".format(proxy)})
- # 使用代理访问
- return html
- except Exception:
- retry_count -= 1
- # 删除代理池中代理
- delete_proxy(proxy)
- return None
- Contents
- --------
- .. toctree::
- :maxdepth: 2
- user/intro.rst
|