[Python] python通过MD5验证网站下载文件的有效性 →→→→→进入此内容的聊天室

来自 , 2020-07-24, 写在 Python, 查看 109 次.
URL http://www.code666.cn/view/2afc4dfb
  1. # -*- coding: cp950 -*-
  2. import sys
  3. import hashlib
  4. #save as md5_study.py
  5.  
  6. def md5(fileName):
  7.     """Compute md5 hash of the specified file"""
  8.     m = hashlib.md5()
  9.     try:
  10.         fd = open(fileName,"rb")
  11.     except IOError:
  12.         print "Reading file has problem:", filename
  13.         return
  14.     x = fd.read()
  15.     fd.close()
  16.     m.update(x)
  17.     return m.hexdigest()
  18.  
  19. if __name__ == "__main__":
  20.     for eachFile in sys.argv[1:]:
  21.         print "%s %s" % (md5(eachFile), eachFile)
  22.  
  23.  
  24. #//python/7138

回复 "python通过MD5验证网站下载文件的有效性"

这儿你可以回复上面这条便签

captcha