优化代码结构

新增双下单方法
修复一直bug
pull/42/head
wenxianping 2018-08-29 19:19:58 +08:00
parent c0d88bc8b7
commit 9c95cc03c1
3 changed files with 7 additions and 11 deletions

View File

@ -1,7 +1,6 @@
#encoding=utf8 #encoding=utf8
import socket import socket
import urllib import requests
import urllib2
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
@ -16,13 +15,12 @@ class proxy:
:return: :return:
""" """
User_Agent = 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0' 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 header['User-Agent'] = User_Agent
for i in range(1, 5): for i in range(1, 5):
url = 'http://www.xicidaili.com/nn/'+str(i) url = 'http://www.xicidaili.com/nn/'+str(i)
req = urllib2.Request(url, headers=header) res = requests.get(url=url, headers=header).content
res = urllib2.urlopen(req).read()
soup = BeautifulSoup(res, "html.parser") soup = BeautifulSoup(res, "html.parser")
ips = soup.findAll('tr') ips = soup.findAll('tr')
@ -45,7 +43,7 @@ class proxy:
for proxy in self.proxy_list: for proxy in self.proxy_list:
proxy_temp = {"http://": proxy} proxy_temp = {"http://": proxy}
try: try:
urllib.urlopen(url, proxies=proxy_temp).read() req = requests.get(url, proxies=proxy_temp).content
write_proxy = proxy+"\n" write_proxy = proxy+"\n"
f.write(write_proxy) f.write(write_proxy)
proxy_num += 1 proxy_num += 1
@ -74,4 +72,4 @@ class proxy:
if __name__ == "__main__": if __name__ == "__main__":
a = proxy() a = proxy()
a.get_filter_proxy() a.main()

View File

@ -88,7 +88,7 @@ class CDNProxy:
def all_cdn(self): def all_cdn(self):
"""获取cdn列表""" """获取cdn列表"""
with open('./cdn_list', 'r') as f: with open('../cdn_list', 'r') as f:
cdn = f.readlines() cdn = f.readlines()
return cdn return cdn
@ -103,6 +103,4 @@ class CDNProxy:
if __name__ == '__main__': if __name__ == '__main__':
cdn = CDNProxy() cdn = CDNProxy()
cdn.get_city_id() cdn.get_cdn_list()
# cdn.get_cdn_list()
cdn.par_csv()

BIN
tkcode

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 13 KiB