how to check if URL cannot be opened

Tim Golden tim.golden at viacom-outdoor.co.uk
Wed Oct 27 12:13:06 EDT 2004


[miodio67 at hotmail.com]
| Im new to python. So I was hoping someone could provide the following.
| How would I go about checking if a user can be opened. For example if
| user provides www.x.com, how would I check if there is such a url?
| What methods would I need to invoke?

<code>
import urllib

DEFAULT_LINK = "http://www.example.com"
while 1:
  print
  link = raw_input ("Enter link [%s]: " % DEFAULT_LINK) or DEFAULT_LINK
  print "Checking link...",
  try:
    urllib.urlopen (link)
  except:
    print "Couldn't open %s - please check the spelling &c." % link
  else:
    break

</code>

TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________



More information about the Python-list mailing list