【发布时间】:2013-07-11 16:54:41
【问题描述】:
我必须通过大量的 ips 搜索特定的 url。我在python中编写了一个脚本来检查端口是否打开,然后使用httplib检查url是否存在,它工作得很好!我的问题是我得到了太多误报,因为一些网络设备在请求我的页面时给出状态 200,并在正文上返回一个带有 400 错误的页面
这是我的代码:
def MyPage(self,ip):
try:
conn = httplib.HTTPConnection(ip)
conn.request("HEAD", "/path/to/mypage.php")
resp = conn.getresponse()
if (resp.status == 200):
return True
else :
return False
except :
return False
【问题讨论】:
标签: python beautifulsoup httplib getresponse