-
Notifications
You must be signed in to change notification settings - Fork 1
/
links_checker.py
35 lines (29 loc) · 952 Bytes
/
links_checker.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
import httplib
from urlparse import urlparse
import socket
import sys
fin = open('test_list_final.txt', 'r')
for line in fin:
(_,fullurl) = line.split('\t')
(fullurl, _) = fullurl.split('\n') # important
url = urlparse(fullurl)
try:
conn = httplib.HTTPConnection(url.netloc)
conn.request('GET', url.path)
resp = conn.getresponse()
if resp.status == 200 or (resp.status >= 300 and resp.status < 400):
fout = open('checked_feeds.txt', 'a')
fout.write(line)
fout.close()
else:
print "%s -> %s" % (fullurl, resp.status)
conn.close()
except socket.error:
errno, errstr = sys.exc_info()[:2]
print "%s -> %s" % (fullurl, errno)
print errstr
except KeyboardInterrupt:
break
except:
print "%s -> Unknown exception" % (fullurl)
fin.close()