File tree 4 files changed +24
-13
lines changed
4 files changed +24
-13
lines changed Original file line number Diff line number Diff line change 1
1
DBName = "PROXIES.db" # 数据库名称
2
2
TabelName = "IPPORT" # 表
3
3
Column1 = "IP_PORT" # 列1
4
- TestTimeOut = 10 # 检测IP可用性设置的超时
4
+
5
+ TestTimeOut = 10 # 检测IP可用性设置的超时,
6
+ # 对IP质量要求不高,就把值设的高一点儿。这样可用IP就会增多
5
7
MaxThreads = 64 # 最大线程数,依据电脑性能修改,性能好的电脑可以设置高一点
8
+ # 最好设置为2的n次方,别问我为什么,我也不知道,这是玄学
9
+
6
10
TestUrl = "https://www.baidu.com/" # 用以检测的网站
7
11
8
12
# 头部代理S
Original file line number Diff line number Diff line change @@ -31,6 +31,8 @@ def GetPageContent(tar_url):
31
31
32
32
33
33
def GetIP ():
34
+ global d
35
+ global ip_list
34
36
thread_list = []
35
37
ips = []
36
38
@@ -50,17 +52,21 @@ def GetIP():
50
52
51
53
for item in d .keys ():
52
54
ips .append (item )
55
+ d .clear ()
53
56
ProxiesDataBase .AddItems (ips )
54
57
55
58
56
59
def RefreshDB ():
60
+ global d
61
+ global ip_list
57
62
ip_list = ProxiesDataBase .GetItems ()
58
63
thread_list = []
59
64
ips = []
60
65
61
- if not ip_list :
66
+ if ip_list . __len__ () < 1 :
62
67
return
63
68
69
+
64
70
for index in range (0 , Config .MaxThreads ):
65
71
thread_list .append (Thread (target = VerifyIp ))
66
72
for item in thread_list :
@@ -69,14 +75,18 @@ def RefreshDB():
69
75
item .join ()
70
76
71
77
ProxiesDataBase .ClearItems ()
78
+
72
79
for item in d .keys ():
73
80
ips .append (item )
81
+ d .clear ()
74
82
ProxiesDataBase .AddItems (ips )
75
83
76
84
77
85
def VerifyIp ():
86
+ global d
78
87
while ip_list :
79
88
tmp_ip_port = ip_list .pop (0 )
89
+ print ("verify ip: {}" .format (tmp_ip_port ))
80
90
proxies = {"http" : "http://{}" .format (tmp_ip_port ), "https" : "https://{}" .format (tmp_ip_port )}
81
91
try :
82
92
url_content = get (Config .TestUrl ,
Original file line number Diff line number Diff line change 1
1
# table IPPORT
2
2
# ip_port TEXT NOT NULL
3
- import random
4
3
import sqlite3
5
- from threading import Thread
6
4
import traceback
5
+
7
6
import Config
8
- import GetIP
9
7
10
8
11
9
def InitDB ():
12
10
db_conn = sqlite3 .connect (Config .DBName )
13
11
try :
14
12
db_conn .execute (
15
- """CREATE TABLE IF NOT EXISTS {} (IP_PORT TEXT NOT NULL PRIMARY KEY );""" .format (Config .TabelName ))
13
+ """CREATE TABLE IF NOT EXISTS {} (IP_PORT TEXT NOT NULL);""" .format (Config .TabelName ))
16
14
db_conn .commit ()
17
15
return True
18
16
except BaseException as e :
@@ -34,15 +32,18 @@ def AddItem(ip_port):
34
32
traceback .print_exc ()
35
33
db_conn .close ()
36
34
35
+
37
36
def AddItems (ip_list ):
37
+ if ip_list .__len__ () < 1 :
38
+ return
39
+
38
40
sql_str = """INSERT INTO IPPORT VALUES """
39
41
40
42
for item in ip_list :
41
43
sql_str += ("('{}')," .format (item ))
42
44
index = sql_str .__len__ ()
43
45
sql_str = sql_str [0 :index - 1 ]
44
46
sql_str += ";"
45
-
46
47
db_conn = sqlite3 .connect (Config .DBName )
47
48
try :
48
49
db_conn .execute (sql_str )
@@ -83,14 +84,10 @@ def GetItems():
83
84
db_conn = sqlite3 .connect (Config .DBName )
84
85
db_cur = db_conn .cursor ()
85
86
try :
86
- tmp = db_cur .execute ("""SELECT * FROM {};""" .format (Config .TabelName )).fetchall ()
87
- for item in tmp :
87
+ for item in db_cur .execute ("""SELECT * FROM {};""" .format (Config .TabelName )).fetchall ():
88
88
ip_list .append (item [0 ])
89
89
except BaseException as e :
90
90
traceback .print_exc ()
91
91
finally :
92
92
db_conn .close ()
93
93
return ip_list
94
-
95
-
96
-
Original file line number Diff line number Diff line change 1
1
import sqlite3
2
-
2
+ import GetIP
3
3
import Config
4
4
import ProxiesDataBase
5
5
import Util
You can’t perform that action at this time.
0 commit comments