index.rst 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. Python爬虫代理IP池
  8. 安装
  9. -----
  10. * 下载代码
  11. .. code-block:: console
  12. $ git clone git@github.com:jhao104/proxy_pool.git
  13. * 安装依赖
  14. .. code-block:: console
  15. $ pip install -r requirements.txt
  16. * 更新配置
  17. .. code-block:: python
  18. HOST = "0.0.0.0"
  19. PORT = 5000
  20. DB_CONN = 'redis://@127.0.0.1:8888'
  21. PROXY_FETCHER = [
  22. "freeProxy01",
  23. "freeProxy02",
  24. # ....
  25. ]
  26. * 启动项目
  27. .. code-block:: console
  28. $ python proxyPool.py schedule
  29. $ python proxyPool.py server
  30. 使用
  31. ______
  32. * API
  33. ============ ======== ================ ==============
  34. Api Method Description Arg
  35. ============ ======== ================ ==============
  36. / GET API介绍 无
  37. /get GET 随机返回一个代理 无
  38. /get_all GET 返回所有代理 无
  39. /get_status GET 返回代理数量 无
  40. /delete GET 删除指定代理 proxy=host:ip
  41. ============ ======== ================ ==============
  42. * 爬虫
  43. .. code-block:: python
  44. import requests
  45. def get_proxy():
  46. return requests.get("http://127.0.0.1:5010/get/").json()
  47. def delete_proxy(proxy):
  48. requests.get("http://127.0.0.1:5010/delete/?proxy={}".format(proxy))
  49. # your spider code
  50. def getHtml():
  51. # ....
  52. retry_count = 5
  53. proxy = get_proxy().get("proxy")
  54. while retry_count > 0:
  55. try:
  56. html = requests.get('http://www.example.com', proxies={"http": "http://{}".format(proxy)})
  57. # 使用代理访问
  58. return html
  59. except Exception:
  60. retry_count -= 1
  61. # 删除代理池中代理
  62. delete_proxy(proxy)
  63. return None
  64. Contents
  65. --------
  66. .. toctree::
  67. :maxdepth: 2
  68. user/intro.rst