MCPcopy Index your code
hub / github.com/Boris-code/feapder / get_proxy_from_http

Function get_proxy_from_http

feapder/network/proxy_pool_old.py:67–91  ·  view source on GitHub ↗

从指定 http 地址获取代理 :param proxy_source_url: :param kwargs: :return:

(proxy_source_url, **kwargs)

Source from the content-addressed store, hash-verified

65
66
67def get_proxy_from_http(proxy_source_url, **kwargs):
68 """
69 从指定 http 地址获取代理
70 :param proxy_source_url:
71 :param kwargs:
72 :return:
73 """
74 filename = tools.get_md5(proxy_source_url) + ".txt"
75 abs_filename = os.path.join(proxy_path, filename)
76 update_interval = kwargs.get("local_proxy_file_cache_timeout", 60)
77 update_flag = 0
78 if not update_interval:
79 # 强制更新
80 update_flag = 1
81 elif not os.path.exists(abs_filename):
82 # 文件不存在则更新
83 update_flag = 1
84 elif time.time() - os.stat(abs_filename).st_mtime > update_interval:
85 # 超过更新间隔
86 update_flag = 1
87 if update_flag:
88 response = requests.get(proxy_source_url, timeout=20)
89 with open(os.path.join(proxy_path, filename), "w") as f:
90 f.write(response.text)
91 return get_proxy_from_file(filename)
92
93
94def get_proxy_from_file(filename, **kwargs):

Callers 1

get_proxy_from_urlFunction · 0.85

Calls 3

get_proxy_from_fileFunction · 0.85
joinMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected