python - Checking if a link is active from an array -
hey guys have array , want check if websites in array active or not.one of websites in array active other not..so find out wrote code like
import httplib = ['www.nri.com','www.kundis.com'] b in i: c = httplib.httpconnection(b) c.request("head", '') if c.getresponse().status == 200: print('web site exists') c2 = httplib.httpconnection(b) c2.request("head",'') if c2.getresponse().status == 302: print('website not exists')
when run code prints website not exists
. when used i[0] , i[1]
instead of b in httplib.httpconnection()
works.
can guys tell me why happening ??..how can make right giving b
parameter in httplib.httpconnection()
.thanx help
the
if c.getresponse().status == 200: print('web site exists')
part outside for
loop, checks status code of last url called inside for
loop.
maybe you're looking this:
import httplib = ['www.nri.com','www.kundis.com'] b in i: print('checking ' + b) c = httplib.httpconnection(b) c.request("head", '') if c.getresponse().status == 200: print('web site exists') if c.getresponse().status == 302: print('website not exists')
Comments
Post a Comment