属性错误:。。。对象没有属性“update”

2024-10-04 01:25:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下代码从一个url列表下载HTML内容。每当我运行它时,我都会收到一个错误消息:“Traceback(最近的一次调用是最后一次):

 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'*

代码如下:

^{pr2}$

我该怎么解决这个问题?在


Tags: 代码in消息url内容列表html错误
1条回答
网友
1楼 · 发布于 2024-10-04 01:25:32

您试图对函数而不是对象调用方法。请致电:

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)

相关问题 更多 >