CheckProxy.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # # -*- coding: utf-8 -*-
  2. # """
  3. # -------------------------------------------------
  4. # File Name: CheckProxy
  5. # Description : used for check getFreeProxy.py
  6. # Author : JHao
  7. # date: 2018/7/10
  8. # -------------------------------------------------
  9. # Change Activity:
  10. # 2018/7/10: CheckProxy
  11. # -------------------------------------------------
  12. # """
  13. # __author__ = 'JHao'
  14. #
  15. # from .getFreeProxy import GetFreeProxy
  16. # from util.utilFunction import verifyProxyFormat
  17. #
  18. #
  19. # from util.LogHandler import LogHandler
  20. #
  21. # log = LogHandler('check_proxy', file=False)
  22. #
  23. #
  24. # class CheckProxy(object):
  25. #
  26. # @staticmethod
  27. # def checkAllGetProxyFunc():
  28. # """
  29. # 检查getFreeProxy所有代理获取函数运行情况
  30. # Returns:
  31. # None
  32. # """
  33. # import inspect
  34. # member_list = inspect.getmembers(GetFreeProxy, predicate=inspect.isfunction)
  35. # proxy_count_dict = dict()
  36. # for func_name, func in member_list:
  37. # log.info(u"开始运行 {}".format(func_name))
  38. # try:
  39. # proxy_list = [_ for _ in func() if verifyProxyFormat(_)]
  40. # proxy_count_dict[func_name] = len(proxy_list)
  41. # except Exception as e:
  42. # log.info(u"代理获取函数 {} 运行出错!".format(func_name))
  43. # log.error(str(e))
  44. # log.info(u"所有函数运行完毕 " + "***" * 5)
  45. # for func_name, func in member_list:
  46. # log.info(u"函数 {n}, 获取到代理数: {c}".format(n=func_name, c=proxy_count_dict.get(func_name, 0)))
  47. #
  48. # @staticmethod
  49. # def checkGetProxyFunc(func):
  50. # """
  51. # 检查指定的getFreeProxy某个function运行情况
  52. # Args:
  53. # func: getFreeProxy中某个可调用方法
  54. #
  55. # Returns:
  56. # None
  57. # """
  58. # func_name = getattr(func, '__name__', "None")
  59. # log.info("start running func: {}".format(func_name))
  60. # count = 0
  61. # for proxy in func():
  62. # if verifyProxyFormat(proxy):
  63. # log.info("{} fetch proxy: {}".format(func_name, proxy))
  64. # count += 1
  65. # log.info("{n} completed, fetch proxy number: {c}".format(n=func_name, c=count))
  66. #
  67. #
  68. # if __name__ == '__main__':
  69. # CheckProxy.checkAllGetProxyFunc()
  70. # CheckProxy.checkGetProxyFunc(GetFreeProxy.freeProxy01)