Python - How to get http response of site -
I want to make a dragon checker to check an http response for a site
I Script other person
script like this
import pycurl import cStringIO import curl re = pycurl.Curl () hobby = cStringIO.StringIO () hdr = cStringIO.StringIO () Curl.setopt (pycurl.URL, 'http://example.org') curl.setopt (pycurl.WRITEFUNCTION, buff.write) curl.setopt (pycurl.HEADERFUNCTION, hdr.write) curl.perform () Print "Status code:% s"% curl.getinfo (pycurl.HTTP_CODE) # - & gt; 200 status_line = hdr.getvalue (). Splitlines () [0] meters = re.match (r'HTTP \ / \ * * s * \ d + \ s * (. *?) \ * $ ', Status_line) if m: status_message = m.groups (1) Other: status_message = '' print '' status message:% s "% status_message # - & gt;
> www.google.com www Facebook.com www.twitter.com
you get a .txt
file for example:
import urllib f = ('list.txt') for L in open f: try: python3.x use # For: x = urllib.request.urlopen ('http: //' + l) Ex = urlib.urlopen ('http: //' + L): Print ('not found') and some: Rint (x.readlines ())
Comments
Post a Comment