擅长:python、mysql、java
<p>我没有发现你的代码有任何问题,只是它几乎不可读。我已经把它改写成这个工作片段:</p>
<pre><code>import httplib
host = 'www.google.com'
directories = ['aosicdjqwe0cd9qwe0d9q2we', 'reader', 'news']
for directory in directories:
conn = httplib.HTTPConnection(host)
conn.request('HEAD', '/' + directory)
url = 'http://{0}/{1}'.format(host, directory)
print ' Trying: {0}'.format(url)
response = conn.getresponse()
print ' Got: ', response.status, response.reason
conn.close()
if response.status == 200:
print ("[!] The subdirectory '{0}' "
"could be interesting.").format(directory)
</code></pre>
<p>输出:</p>
<pre><code>$ python snippet.py
Trying: http://www.google.com/aosicdjqwe0cd9qwe0d9q2we
Got: 404 Not Found
Trying: http://www.google.com/reader
Got: 302 Moved Temporarily
Trying: http://www.google.com/news
Got: 200 OK
[!] The subdirectory 'news' could be interesting.
</code></pre>
<p>另外,我确实使用了<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4" rel="nofollow">HEAD</a>HTTP请求而不是GET,因为如果您不需要内容并且只对状态代码感兴趣,那么它会更有效。</p>