Home > other >  Please instruct AttributeError: '_hashlib. The HASH object has no attribute' updata '
Please instruct AttributeError: '_hashlib. The HASH object has no attribute' updata '

Time:11-19

Program a small white, recently for a period of time to learn python the crawler, encountered a program always pass, specially to BBS to consult ace, please tell know,
The import re
The import requests
The import hashlib
The import time


Def get_index (url) :
Respose=requests. Get (url)
If respose. Status_code==200:
Return respose. Text

Def parse_index (res) :
Urls=re. The.findall (r '. *? Href="https://bbs.csdn.net/topics/(. *?) "', res, re S) # re. S to transform text information into 1 row matching
Return urls

# def save (url) :


Def get_detail (urls) :
For the url in urls:
If not a url. Startswith (' HTTP ') :
Url='http://www.xiaohuar.com%s' % url
Result=requests. Get (url)
If the result. Status_code==200:
Mp4_url_list=re. The.findall (r 'id="media". *? SRC="https://bbs.csdn.net/topics/(. *?) "', the result. The text, re S)
If mp4_url_list:
Mp4_url=mp4_url_list [0]
Print (mp4_url)
# save (mp4_url)
Video=requests. Get (url)
If video. Status_code==200:
M=hashlib md5 ()
M.u pdata (url encode (' utf-8))
M.u pdata (STR (time. Time ()). The encode (' utf-8))
Filename=r '% s.m p4' % m.h exdigest ()
'D: \ \ shipin2 filepath=r % s' % filename
With the open (filepath, 'wb) as f:
F.w rite (video content)




Def the main () :
For I in range (5) :
Res1=get_index (' http://www.xiaohuar.com/list-3-%s.html '% I)
Res2=parse_index (res1)
Get_detail (res2)

If __name__=="__main__ ':
The main ()
The program will then run in PyCharm, results suggest:
C: \ Users \ lenovo \ Anaconda3 \ python exe C:/Users/lenovo/PycharmProjects/python/MP45 py
https://mvvideo5.meitudata.com/570afb877331d7952.mp4
Traceback (the most recent call last) :
The File "C:/Users/lenovo/PycharmProjects/Python/MP45 py", line 65, in & lt; module>
The main ()
The File "C:/Users/lenovo/PycharmProjects/Python/MP45 py", line 62, the main in
Get_detail (res2)
The File "C:/Users/lenovo/PycharmProjects/Python/MP45 py", 48, the line in get_detail
M.u pdata (url encode (' utf-8))
AttributeError: '_hashlib. The HASH object has no attribute' updata '

Process is over, exit code 1
Please instruct

CodePudding user response:

The update, not updata

CodePudding user response:

Moderator has been answered, and the site of mp4 resources has a problem,

CodePudding user response:

Change the updata to update

CodePudding user response:

Ha ha ha and I a mistake, his error code means hashlib inside the bag without updata method, you change the updata to update
  • Related