Python 测试URL是否存在

Python 测试URL是否存在,python,curl,Python,Curl,测试python中是否存在URL的最佳方法是什么?我目前使用cURL,但我想切换到python 在cURL中,我使用 curl http://www.google.com | tidy -i import httplib try: url = httplib.HTTPConnection('yahoo.com') url.connect() except httplib.HTTPException as ex: print "not connected" 与bash

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

在cURL中,我使用

curl http://www.google.com | tidy -i
import httplib

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

与bash脚本一起使用,最快的方法可能是

curl http://www.google.com | tidy -i
import httplib

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

最快的方法大概是

curl http://www.google.com | tidy -i
import httplib

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

最快的方法大概是

curl http://www.google.com | tidy -i
import httplib

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

最快的方法大概是

curl http://www.google.com | tidy -i
import httplib

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