Hi all,
I looked a little bit at the urllib and it all looks fairly easy.
What I didn't see, if it is there, was how to know or identify if a page
was successfully downloaded. I want to do tests to see if a connection
to a webpage was successful by parsing whatever came back.
Will this be the easiest way of doing this or is there a different way
of testing the availability of webpages? Let's say I can connect to a
webpage, but it failed to upload 100%, how will I know that the
connection was not 100% successful? I'm not very familiar with url
parsing and HTML to know if there are other indicators to notify me if a
page or any web access is possible.
Once this was done, can I add features to say how fast the page was
downloaded?
Thanks
Johan
I've just finished writing a smoke test engine after releasing new webpages. I use httplib.HTTPConnection classes.
Here is an example:
import urlparse, httplib
class SiteCheck:
reqtype = 'POST'
def __init__(self, url):
self.url = ""> pieces = urlparse.urlparse(url)
self.hostname = pieces[1]
self.conn = httplib.HTTPConnection(self.hostname)
def run(self):
self.conn.request(self.reqtype, self.url )
response = self.conn.getresponse()
method_name = 'response_%d' % response.status
try:
method = getattr(self, method_name)
except AttributeError:
self.response_default(response)
else:
method(response)
def response_default(self, response):
self.result = '%d %s' % (response.status, response.reason)
def response_200(self, response):
self.result = response.reason # "OK"
def response_302(self, response):
self.result = response.msg['Location'] # 302 redirect
Hopefully this will give you some ideas.
-Arcege
--
There's so many different worlds,
So many different suns.
And we have just one world,
But we live in different ones.
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor