擅长:python、mysql、java
<p>检查网站是否存在:</p>
<pre><code>import httplib
from httplib import HTTP
from urlparse import urlparse
def checkUrl(url):
p = urlparse(url)
h = HTTP(p[1])
h.putrequest('HEAD', p[2])
h.endheaders()
return h.getreply()[0] == httplib.OK
</code></pre>
<p>我们只获取给定URL的头并检查web服务器的响应代码。在</p>
<p><strong>更新:</strong>最后一行根据Daenyth的备注进行修改。在</p>