精简了utility代码
This commit is contained in:
parent
9568db0946
commit
2b53e18957
28
utility.py
28
utility.py
@ -15,18 +15,9 @@ def encrypt(t):
|
||||
cipher_text = b64encode(cipher.encrypt(t.encode()))
|
||||
return cipher_text.decode()
|
||||
|
||||
|
||||
def md5(s):
|
||||
import hashlib
|
||||
m = hashlib.md5()
|
||||
m.update(s.encode())
|
||||
return m.hexdigest()
|
||||
|
||||
|
||||
def cap_recognize(cap):
|
||||
return DdddOcr().classification(denoise(cap))
|
||||
|
||||
|
||||
def denoise(cap):
|
||||
img = Image.open(BytesIO(cap))
|
||||
steps = ((1, 1), (1, 0), (1, -1), (0, 1), (0, -1), (-1, 1), (-1, 0), (-1, -1))
|
||||
@ -55,22 +46,3 @@ def denoise(cap):
|
||||
buf = BytesIO()
|
||||
img.save(buf, format='PNG')
|
||||
return buf.getvalue()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import requests
|
||||
import re
|
||||
|
||||
bjySession = requests.session()
|
||||
bjySession.timeout = 5 # set session timeout
|
||||
touch = bjySession.get(url="https://m.bjyouth.net/site/login")
|
||||
capUrl = "https://m.bjyouth.net" + re.findall(
|
||||
r'src="(/site/captcha.+)" alt=', touch.text)[0]
|
||||
cap1 = bjySession.get(url=capUrl).content
|
||||
cap2 = denoise(cap1)
|
||||
|
||||
img = Image.open(BytesIO(cap1))
|
||||
img.show()
|
||||
|
||||
img = Image.open(BytesIO(cap2))
|
||||
img.show()
|
||||
|
Loading…
x
Reference in New Issue
Block a user