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?
Ops, sorry, the SSL parameter isn't being used there, so you can delete it.import urllib2
import socket
def checkUrl(url, timeout=5, SSL=0):
"""Checks an url for a python version greater
than 2.3.3.
"""
defTimeOut=socket.getdefaulttimeout()
socket.setdefaulttimeout(timeout)
found=1
try:
urllib2.urlopen(url)
except (urllib2.HTTPError, urllib2.URLError,
socket.error, socket.sslerror):
found=0
socket.setdefaulttimeout(defTimeOut)
return found
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.