I have the following code to download HTML content from a list of URLs. Whenever I run it I get an error that says "Traceback (most recent call last):
File "*******", line 16, in <module>
**hashMessage = computeMD5(url)**
File "*******", line 13, in computeMD5
**m.update(message)**
*AttributeError: 'builtin_function_or_method' object has no attribute 'update'*
and here is the code:
import hashlib
from hashlib import md5
import os
fh = open("****.txt", 'r')
for line in fh:
url = line
url = url.replace('\n', '')
def computeMD5(message):
m = hashlib.md5
m.update(message)
return m.hexdigest()
hashMessage = computeMD5(url)
print hashMessage
os.system(" wget -O /desktop/Html" + hashMessage + ".txt " + url)
How can I fix this?
You are attempting to call a method on a function and not an object. Instead call:
import hashlib
from hashlib import md5
import os
fh = open("****.txt", 'r')
for line in fh:
url = line
url = url.replace('\n', '')
def computeMD5(message):
m = hashlib.md5() # instead of m = hashlib.md5
m.update(message)
return m.hexdigest()
hashMessage = computeMD5(url)
print hashMessage
os.system(" wget -O /desktop/Html" + hashMessage + ".txt " + url)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.