删除cdn提示

pull/112/head
wenxianping 6 years ago
parent ac69e2c9e0
commit a9cf9c6c6c

@ -71,56 +71,8 @@ class CDNProxy:
# print(i.replace("\n", "")) # print(i.replace("\n", ""))
if i and "kyfw.12306.cn:443" not in i: if i and "kyfw.12306.cn:443" not in i:
cdn.append(i.replace("\n", "")) cdn.append(i.replace("\n", ""))
print(cdn)
return 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__': if __name__ == '__main__':
cdn = CDNProxy() cdn = CDNProxy()

@ -153,7 +153,7 @@ class select:
rep = http.send(urls) rep = http.send(urls)
if rep and "message" not in rep and (datetime.datetime.now() - start_time).microseconds / 1000 < 500: if rep and "message" not in rep and (datetime.datetime.now() - start_time).microseconds / 1000 < 500:
if cdn[i].replace("\n", "") not in self.cdn_list: # 如果有重复的cdn则放弃加入 if cdn[i].replace("\n", "") not in self.cdn_list: # 如果有重复的cdn则放弃加入
print(u"加入cdn {0}".format(cdn[i].replace("\n", ""))) # print(u"加入cdn {0}".format(cdn[i].replace("\n", "")))
self.cdn_list.append(cdn[i].replace("\n", "")) self.cdn_list.append(cdn[i].replace("\n", ""))
print(u"所有cdn解析完成...") print(u"所有cdn解析完成...")

@ -6,6 +6,7 @@ from time import sleep
import requests import requests
from config import logger from config import logger
def _set_header_default(): def _set_header_default():
header_dict = OrderedDict() header_dict = OrderedDict()
header_dict["Accept"] = "application/json, text/plain, */*" header_dict["Accept"] = "application/json, text/plain, */*"
@ -25,6 +26,7 @@ class HTTPClient(object):
""" """
self.initS() self.initS()
self._cdn = None self._cdn = None
self._proxies = None
def initS(self): def initS(self):
self._s = requests.Session() self._s = requests.Session()
@ -126,7 +128,10 @@ class HTTPClient(object):
try: try:
# sleep(urls["s_time"]) if "s_time" in urls else sleep(0.001) # sleep(urls["s_time"]) if "s_time" in urls else sleep(0.001)
sleep(s_time) sleep(s_time)
requests.packages.urllib3.disable_warnings() try:
requests.packages.urllib3.disable_warnings()
except:
pass
response = self._s.request(method=method, response = self._s.request(method=method,
timeout=2, timeout=2,
url="https://" + url_host + req_url, url="https://" + url_host + req_url,

Loading…
Cancel
Save