使用异常进行 md5 搜索
import httplib
import re
md5 = raw_input('Enter MD5: ')
conn = httplib.HTTPConnection("www.md5.rednoize.com")
conn.request("GET", "?q="+ md5)
try:
response = conn.getresponse()
data = response.read()
result = re.findall('<div id="result" >(.+?)</div', data)
print result
except:
print "couldnt find the hash"
raw_input()
我知道我可能执行了错误的代码,但是我应该使用哪个异常?如果找不到哈希,则引发异常并打印“无法找到哈希”
import httplib
import re
md5 = raw_input('Enter MD5: ')
conn = httplib.HTTPConnection("www.md5.rednoize.com")
conn.request("GET", "?q="+ md5)
try:
response = conn.getresponse()
data = response.read()
result = re.findall('<div id="result" >(.+?)</div', data)
print result
except:
print "couldnt find the hash"
raw_input()
I know I'm probably implementing the code wrong, but which exception should I use for this? if it cant find the hash then raise an exception and print "couldnt find the hash"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于 re.findall 不会引发异常,因此这可能不是您想要检查结果的方式。相反,你可以写类似的东西
Since re.findall doesn't raise exceptions, that's probably not how you want to check for results. Instead, you could write something like
如果你真的想有一个例外,你必须定义它:
If you realy like to have an exception there you have to define it: