testing a website from python

M

M.N.A.Smadi

hi;

I just want to test that a given website is up or not from a python
script. I thought of using wget as an os command. Any better ideas?

thanks
moe smadi
 
B

Benji York

matt said:
Here's something I did recently at work.
It contains unittest code and is using
urllib2.
http://blog.spikesource.com/pyhton_testcases.htm

If you want to test web sites, you might be interested in
zope.testbrowser (currently Zope 3 only, but fixing that is on my to do
list).

You can see an example testbrowser test (which is also both its README
and its unit tests) at
http://svn.zope.org/*checkout*/Zope...ion/src/zope/testbrowser/README.txt?rev=38050

If there is any interest I'll try to package up a stand-alone version in
the next few days.
 
A

Achim Domma (SyynX Solutions GmbH)

Benji said:
If there is any interest I'll try to package up a stand-alone version in
the next few days.

I think that would be a very usefull tool. Currently I'm using httpunit
with Jython but a python only tool would be much nicer.

regards,
Achim
 
J

Josef Meile

Hi,
I just want to test that a given website is up or not from a python
script. I thought of using wget as an os command. Any better ideas?
Here is how I did it:

import urllib2
import socket
def checkUrl(url, timeout=1):
"""Checks an url for a python version greater
than 2.3.3.

Note: For me isn't important the kind of
HTTP Error. If you want to know it,
then take a look at the existent
solutions like CMFLinkChecker and
see how they extract the code from
the error message.
"""
error={'code':1, 'msg':'Success'}
defTimeOut=socket.getdefaulttimeout()
socket.setdefaulttimeout(timeout)
try:
urllib2.urlopen(url)
except (urllib2.HTTPError, urllib2.URLError,
socket.error, socket.sslerror):
error['code']=-2
error['msg']="The link: \"${link}\" couldn't be validated"
except:
socket.setdefaulttimeout(defTimeOut)
raise

socket.setdefaulttimeout(defTimeOut)
return error
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top