Skip to content

Commit

Permalink
优化代码结构
Browse files Browse the repository at this point in the history
新增双下单方法
修复一直bug
  • Loading branch information
testerSunshine committed Aug 29, 2018
1 parent c0d88bc commit 9c95cc0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
12 changes: 5 additions & 7 deletions agency/agency_tools.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#encoding=utf8
import socket
import urllib
import urllib2
import requests
from bs4 import BeautifulSoup


Expand All @@ -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')
Expand All @@ -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
Expand Down Expand Up @@ -74,4 +72,4 @@ def main(self):

if __name__ == "__main__":
a = proxy()
a.get_filter_proxy()
a.main()
6 changes: 2 additions & 4 deletions agency/cdn_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Binary file modified tkcode
Binary file not shown.

0 comments on commit 9c95cc0

Please sign in to comment.