3

For a url entered by the user :

check that is any webserver hosting the domain name or not ?

For example :

url='laksjdfaksdfjajdfaljewoifjadslkjflkasjrlwkejk.com' 

Now, the above url does-not exists, so there is no point of check for any HTTP error codes since, no server is there that will reply back.

So, how to detect such url ?

isServerUp() ? 

1 Answer 1

2

This should open the url for you; obviously change how you want to say that the url has failed to open. The docs are: http://docs.python.org/library/urllib2.html

from urllib2 import * req = Request(url) # Try to open the url try: reponse = urlopen(req) except HTTPError, e: url = None except URLError, e: url = None 

EDIT: Indentation fixed

Sign up to request clarification or add additional context in comments.

6 Comments

Please fix the indentation, I don't think that will run.
@dancek thank you, that's what I get for copying and pasting.
+1, but please note that import * is usually a bad practice cluttering your namespace and creating less maintainable code. either explicitly import what you need, or import the module.
its giving error : ValueError: unknown url type: thisisaurlthatdoesnotexists.com
@Yugal the url must be a string and must contain the http part: ("http://thisisaurlthatdoesnotexists.com")
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.