testGetFreeProxy.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # -*- coding: utf-8 -*-
  2. """
  3. -------------------------------------------------
  4. File Name: testGetFreeProxy
  5. Description : test model ProxyGetter/getFreeProxy
  6. Author : J_hao
  7. date: 2017/7/31
  8. -------------------------------------------------
  9. Change Activity:
  10. 2017/7/31:function testGetFreeProxy
  11. -------------------------------------------------
  12. """
  13. __author__ = 'J_hao'
  14. import re
  15. import sys
  16. import requests
  17. try:
  18. from importlib import reload # py3 实际不会实用,只是为了不显示语法错误
  19. except:
  20. reload(sys)
  21. sys.setdefaultencoding('utf-8')
  22. sys.path.append('..')
  23. from ProxyGetter.getFreeProxy import GetFreeProxy
  24. from Config.ConfigGetter import config
  25. # noinspection PyPep8Naming
  26. def testGetFreeProxy():
  27. """
  28. test class GetFreeProxy in ProxyGetter/GetFreeProxy
  29. :return:
  30. """
  31. proxy_getter_functions = config.proxy_getter_functions
  32. for proxyGetter in proxy_getter_functions:
  33. proxy_count = 0
  34. for proxy in getattr(GetFreeProxy, proxyGetter.strip())():
  35. if proxy:
  36. print('{func}: fetch proxy {proxy},proxy_count:{proxy_count}'.format(func=proxyGetter, proxy=proxy,
  37. proxy_count=proxy_count))
  38. proxy_count += 1
  39. # assert proxy_count >= 20, '{} fetch proxy fail'.format(proxyGetter)
  40. if __name__ == '__main__':
  41. testGetFreeProxy()