mardi 22 mars 2016

Check Response Time, Length and URL status(get code 200,404 etc ) using Python

I have multiple URL's for that I want to check the status like URL Status(return code like 200,404 etc). Below is the code that will getcode. I want to check response time, length from the same code. Can anyone help me to modify below code to find response time,length and getcode for multiple urls.

import socket
from urllib2 import urlopen, URLError, HTTPError

import urllib
socket.setdefaulttimeout( 23 )  # timeout in seconds
#print "---------URL----------", " ---Status Code---"
url='https://www.google.com'

    try :
      response = urlopen( url )
    except HTTPError, e:
        print 'The server couldn\'t fulfill the request. Reason:', str(e.code)
        #Want to get code for that but its not showing

    except URLError, e:
        print 'We failed to reach a server. Reason:', str(e.reasonse)
        #Want to get code for that but its not showing


    else :

        code=urllib.urlopen(url).getcode()
        **#here getcode is working
        print url,"-------->", code
        #print 'got response!' 




Aucun commentaire:

Enregistrer un commentaire