测试是否存在URL

时间:2014-07-17 10:07:55

标签: python curl

测试python中是否存在URL的最佳方法是什么,我目前使用cURL但是我想切换到使用python

在cURL中我使用类似

的东西
curl http://www.google.com | tidy -i

与bash脚本一起

1 个答案:

答案 0 :(得分:3)

最快的方法可能是

import httplib

try:
    url = httplib.HTTPConnection('yahoo.com')
    url.connect()
except httplib.HTTPException as ex:
    print "not connected"