-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_webstatus_200.py
55 lines (48 loc) · 1.41 KB
/
get_webstatus_200.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
# -*- conding:utf-8 -*-
import urllib.request
import urllib.error
import threading
import queue
import time
q=queue.Queue()
list = []
name = input("文件名:")
with open('%s'%(name), 'r') as f:
for i in f.readlines():
i = i.strip()
q.put(i)
print(q.qsize()) #显示一共多少个链接
class mythread(threading.Thread):
def __init__(self,q):
threading.Thread.__init__(self)
self.q = q
def run(self):
while self.q.empty() == False: #判断q是否还有链接
url = self.q.get()
urls = "http://"+url
try:
opurl = urllib.request.urlopen(urls, timeout=3).code
print(url + " --------->" + str(opurl))
list.append(urls)
except urllib.error.URLError as e:
print(e)
e = str(e)
if 'SSL' in e:
list.append("https://" + url)
print("https://" + url + " ---> https")
print(urls + ' --->错误')
except:
print(urls + " -------->错误!!")
threads = []
for i in range(10): #多线程启动
thread1 = mythread(q)
thread1.start()
threads.append(thread1)
# 等待所有线程完成
for t in threads:
t.join()
print ("退出主线程")
with open('%s_200.txt'%(name),'a') as f:
for i in list:
f.write(i+'\n')