驗證碼登入及例項

2021-09-01 14:32:05 字數 2171 閱讀 2660

圖形驗證碼、極驗驗證碼

(1)手動輸入

(2)光學識別 ocr

畢竟是機器,一般識別率 80% 僅限於簡單的圖形驗證碼

指令識別,tesseract 名字 lala 0%

**識別,60%

pip install pytesseract

pip install pillow

(3)打碼平台

雲打碼

import requests

from bs4 import beautifulsoup

import urllib.request

import pytesseract

from pil import image

from pil import imageenhance

import time

def shibie(imagepath):

# 開啟

img = image.open(imagepath)

img = img.convert('rgb')

enhancer = imageenhance.color(img)

enhancer = enhancer.enhance(0)

enhancer = imageenhance.brightness(enhancer)

enhancer = enhancer.enhance(2)

enhancer = imageenhance.contrast(enhancer)

enhancer = enhancer.enhance(8)

enhancer = imageenhance.sharpness(enhancer)

img = enhancer.enhance(20)

# 轉化為灰度

img = img.convert('l')

# 二值化處理

threshold = 140

table =

for i in range(256):

if i < threshold:

else:

out = img.point(table, '1')

return pytesseract.image_to_string(img)

# 要使用會話。

s = requests.session()

i = 1

while 1:

url = ''

headers =

r_get = s.get(url=url, headers=headers)

soup = beautifulsoup(r_get.text, 'lxml')

# 提取驗證碼的src屬性

image_src = '' + soup.select('#imgcode')[0]['src']

# urllib.request.urlretrieve(image_src, 'code.png')

r_image = s.get(url=image_src, headers=headers)

with open('code.png', 'wb') as fp:

fp.write(r_image.content)

# 獲取表單隱藏框裡面的資料

views = soup.select('#__viewstate')[0]['value']

viewg = soup.select('#__viewstategenerator')[0]['value']

# 讓使用者輸入驗證碼

code = shibie('code.png')

# 傳送post請求

# 判斷有沒有登入成功

if '退出登入' in r_post.text:

print('恭喜你第--%s--次登入成功' % i)

break

print('不要灰心,這是你第--%s--次失敗' % i)

i += 1

time.sleep(2)

springboot 驗證碼登入例項

很久沒自己來寫過部落格了,因為在現在的開發裡面最多就做個crub的操作,別的偶爾修改一下介面,沒有完整的自己做過出來乙個東西過,今天寫這個部落格的目的就是要自己一步一步的寫乙個小的記賬功能的web端服務。這個是詳細的目錄 下面給出來的是驗證碼的生成類,頁面上通過src來到這個介面裡面,從而獲得生成的...

登入驗證碼

生成驗證碼 指定驗證碼的長度 public static string createvalidatecode int length 生成隨機數字 for int i 0 i length i 抽取隨機數字 for int i 0 i length i 生成驗證碼 for int i 0 i leng...

登入驗證碼C

一.新建乙個checkcode.aspx using system using system.data using system.configuration using system.collections using system.web using system.web.security usi...