index.rst 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. .. ProxyPool documentation master file, created by
  2. sphinx-quickstart on Wed Jul 8 16:13:42 2020.
  3. You can adapt this file completely to your liking, but it should at least
  4. contain the root `toctree` directive.
  5. ProxyPool
  6. =====================================
  7. ::
  8. ****************************************************************
  9. *** ______ ********************* ______ *********** _ ********
  10. *** | ___ \_ ******************** | ___ \ ********* | | ********
  11. *** | |_/ / \__ __ __ _ __ _ | |_/ /___ * ___ | | ********
  12. *** | __/| _// _ \ \ \/ /| | | || __// _ \ / _ \ | | ********
  13. *** | | | | | (_) | > < \ |_| || | | (_) | (_) || |___ ****
  14. *** \_| |_| \___/ /_/\_\ \__ |\_| \___/ \___/ \_____/ ****
  15. **** __ / / *****
  16. ************************* /___ / *******************************
  17. ************************* ********************************
  18. ****************************************************************
  19. Python爬虫代理IP池
  20. 安装
  21. -----
  22. * 下载代码
  23. .. code-block:: console
  24. $ git clone git@github.com:jhao104/proxy_pool.git
  25. * 安装依赖
  26. .. code-block:: console
  27. $ pip install -r requirements.txt
  28. * 更新配置
  29. .. code-block:: python
  30. HOST = "0.0.0.0"
  31. PORT = 5000
  32. DB_CONN = 'redis://@127.0.0.1:8888'
  33. PROXY_FETCHER = [
  34. "freeProxy01",
  35. "freeProxy02",
  36. # ....
  37. ]
  38. * 启动项目
  39. .. code-block:: console
  40. $ python proxyPool.py schedule
  41. $ python proxyPool.py server
  42. 使用
  43. ______
  44. * API
  45. ============ ======== ================ ==============
  46. Api Method Description Arg
  47. ============ ======== ================ ==============
  48. / GET API介绍 无
  49. /get GET 随机返回一个代理 无
  50. /get_all GET 返回所有代理 无
  51. /get_status GET 返回代理数量 无
  52. /delete GET 删除指定代理 proxy=host:ip
  53. ============ ======== ================ ==============
  54. * 爬虫
  55. .. code-block:: python
  56. import requests
  57. def get_proxy():
  58. return requests.get("http://127.0.0.1:5010/get/").json()
  59. def delete_proxy(proxy):
  60. requests.get("http://127.0.0.1:5010/delete/?proxy={}".format(proxy))
  61. # your spider code
  62. def getHtml():
  63. # ....
  64. retry_count = 5
  65. proxy = get_proxy().get("proxy")
  66. while retry_count > 0:
  67. try:
  68. html = requests.get('http://www.example.com', proxies={"http": "http://{}".format(proxy)})
  69. # 使用代理访问
  70. return html
  71. except Exception:
  72. retry_count -= 1
  73. # 删除代理池中代理
  74. delete_proxy(proxy)
  75. return None
  76. Contents
  77. --------
  78. .. toctree::
  79. :maxdepth: 2
  80. user/index
  81. changelog