精简了utility代码
This commit is contained in:
parent
9568db0946
commit
2b53e18957
30
utility.py
30
utility.py
@ -15,18 +15,9 @@ def encrypt(t):
|
|||||||
cipher_text = b64encode(cipher.encrypt(t.encode()))
|
cipher_text = b64encode(cipher.encrypt(t.encode()))
|
||||||
return cipher_text.decode()
|
return cipher_text.decode()
|
||||||
|
|
||||||
|
|
||||||
def md5(s):
|
|
||||||
import hashlib
|
|
||||||
m = hashlib.md5()
|
|
||||||
m.update(s.encode())
|
|
||||||
return m.hexdigest()
|
|
||||||
|
|
||||||
|
|
||||||
def cap_recognize(cap):
|
def cap_recognize(cap):
|
||||||
return DdddOcr().classification(denoise(cap))
|
return DdddOcr().classification(denoise(cap))
|
||||||
|
|
||||||
|
|
||||||
def denoise(cap):
|
def denoise(cap):
|
||||||
img = Image.open(BytesIO(cap))
|
img = Image.open(BytesIO(cap))
|
||||||
steps = ((1, 1), (1, 0), (1, -1), (0, 1), (0, -1), (-1, 1), (-1, 0), (-1, -1))
|
steps = ((1, 1), (1, 0), (1, -1), (0, 1), (0, -1), (-1, 1), (-1, 0), (-1, -1))
|
||||||
@ -54,23 +45,4 @@ def denoise(cap):
|
|||||||
|
|
||||||
buf = BytesIO()
|
buf = BytesIO()
|
||||||
img.save(buf, format='PNG')
|
img.save(buf, format='PNG')
|
||||||
return buf.getvalue()
|
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