testGetFreeProxy.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 Util.GetConfig import GetConfig
  25. # noinspection PyPep8Naming
  26. def testGetFreeProxy():
  27. """
  28. test class GetFreeProxy in ProxyGetter/GetFreeProxy
  29. :return:
  30. """
  31. gc = GetConfig()
  32. proxy_getter_functions = gc.proxy_getter_functions
  33. for proxyGetter in proxy_getter_functions:
  34. proxy_count = 0
  35. for proxy in getattr(GetFreeProxy, proxyGetter.strip())():
  36. if proxy:
  37. print('{func}: fetch proxy {proxy},proxy_count:{proxy_count}'.format(func=proxyGetter, proxy=proxy,proxy_count=proxy_count))
  38. proxy_count += 1
  39. #assert proxy_count >= 20, '{} fetch proxy fail'.format(proxyGetter)
  40. if __name__ == '__main__':
  41. testGetFreeProxy()