diff --git a/agency/agency_tools.py b/agency/agency_tools.py index dcdcdb82..eafd0def 100755 --- a/agency/agency_tools.py +++ b/agency/agency_tools.py @@ -1,7 +1,6 @@ #encoding=utf8 import socket -import urllib -import urllib2 +import requests from bs4 import BeautifulSoup @@ -16,13 +15,12 @@ def get_proxy(self): :return: """ User_Agent = 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0' - header = {} + header = dict() header['User-Agent'] = User_Agent for i in range(1, 5): url = 'http://www.xicidaili.com/nn/'+str(i) - req = urllib2.Request(url, headers=header) - res = urllib2.urlopen(req).read() + res = requests.get(url=url, headers=header).content soup = BeautifulSoup(res, "html.parser") ips = soup.findAll('tr') @@ -45,7 +43,7 @@ def filter_proxy(self): for proxy in self.proxy_list: proxy_temp = {"http://": proxy} try: - urllib.urlopen(url, proxies=proxy_temp).read() + req = requests.get(url, proxies=proxy_temp).content write_proxy = proxy+"\n" f.write(write_proxy) proxy_num += 1 @@ -74,4 +72,4 @@ def main(self): if __name__ == "__main__": a = proxy() - a.get_filter_proxy() \ No newline at end of file + a.main() \ No newline at end of file diff --git a/agency/cdn_utils.py b/agency/cdn_utils.py index b4d2238d..2182a2e8 100755 --- a/agency/cdn_utils.py +++ b/agency/cdn_utils.py @@ -88,7 +88,7 @@ def get_cdn_list(self): def all_cdn(self): """获取cdn列表""" - with open('./cdn_list', 'r') as f: + with open('../cdn_list', 'r') as f: cdn = f.readlines() return cdn @@ -103,6 +103,4 @@ def par_csv(self): if __name__ == '__main__': cdn = CDNProxy() - cdn.get_city_id() - # cdn.get_cdn_list() - cdn.par_csv() + cdn.get_cdn_list() diff --git a/tkcode b/tkcode index ce239c28..ffd7fe94 100755 Binary files a/tkcode and b/tkcode differ