|
|
|
@ -71,56 +71,8 @@ class CDNProxy:
|
|
|
|
|
# print(i.replace("\n", ""))
|
|
|
|
|
if i and "kyfw.12306.cn:443" not in i:
|
|
|
|
|
cdn.append(i.replace("\n", ""))
|
|
|
|
|
print(cdn)
|
|
|
|
|
return cdn
|
|
|
|
|
|
|
|
|
|
def get_cdn_list(self):
|
|
|
|
|
"""
|
|
|
|
|
筛选代理
|
|
|
|
|
:return:
|
|
|
|
|
"""
|
|
|
|
|
f = self.open_cdn_file()
|
|
|
|
|
url = self.urlConf["cdn_list"]["req_url"]
|
|
|
|
|
num = 1
|
|
|
|
|
f.seek(0)
|
|
|
|
|
f.truncate()
|
|
|
|
|
for guid in self.city_list:
|
|
|
|
|
data = {"guid": guid,
|
|
|
|
|
"host": "kyfw.12306.cn",
|
|
|
|
|
"ishost": 0,
|
|
|
|
|
"encode": "HJXhdRqjh5yCF6G/AZ6EDk9faB1oSk5r",
|
|
|
|
|
"checktype": 0}
|
|
|
|
|
try:
|
|
|
|
|
cdn_info = self.httpClint.post(url, data, headers=self._set_header(), timeout=self.timeout).content
|
|
|
|
|
print(cdn_info)
|
|
|
|
|
if cdn_info:
|
|
|
|
|
split_cdn = cdn_info.split("(")[1].rstrip(")").replace("{", "").replace("}", "").split(",")
|
|
|
|
|
local_dict = collections.OrderedDict()
|
|
|
|
|
for i in split_cdn:
|
|
|
|
|
splits = i.split(":")
|
|
|
|
|
local_dict[splits[0]] = splits[2] if splits[0] == "result" else splits[1]
|
|
|
|
|
if local_dict and "state" in local_dict and local_dict["state"] == "1":
|
|
|
|
|
if "responsetime" in local_dict and local_dict["responsetime"].find("毫秒") != -1 and int(filter(str.isdigit, local_dict["responsetime"])) < 100:
|
|
|
|
|
f.write(json.dumps(local_dict)+"\n")
|
|
|
|
|
num += 1
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(e)
|
|
|
|
|
print(u"本次cdn获取完成,总个数{0}".format(num))
|
|
|
|
|
|
|
|
|
|
def all_cdn(self):
|
|
|
|
|
"""获取cdn列表"""
|
|
|
|
|
with open('cdn_list', 'r') as f:
|
|
|
|
|
cdn = f.readlines()
|
|
|
|
|
return cdn
|
|
|
|
|
|
|
|
|
|
def par_csv(self):
|
|
|
|
|
cdn_csv = csv.reader(open("../cdn1.csv", "r"))
|
|
|
|
|
for c in cdn_csv:
|
|
|
|
|
cdn_re = re.compile(r'https://(\S+)/otn/index/init')
|
|
|
|
|
cdn_ip = re.findall(cdn_re, c[0])
|
|
|
|
|
if cdn_ip and c[2] == "200":
|
|
|
|
|
print(cdn_ip[0])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
cdn = CDNProxy()
|
|
|
|
|