在公司上班閑的沒事干,學點selenium
先安裝selenium
pip install selenium
出現報錯
Cannot uninstall certifi None
╰─> The package's contents are unknown: no RECORD file was found for certifi.hint: You might be able to recover from this via: pip install --force-reinstall --no-deps certifi==2024.8.30
解決方式:
定位到site-packages
目錄,刪掉certifi
文件夾,和所有與.dist-info
相關的文件夾
之后執行
pip install certifi selenium
即可安裝成功
就可以開始寫腳本了
寫腳本過程中,需要驗證一個圖片的驗證碼,主要是4位數字的驗證碼
可以先使用pytesseract
識別驗證碼
使用的時候電腦要先安裝ocr
https://github.com/UB-Mannheim/tesseract/wiki
安裝成功之后,要修改對應的環境變量
具體使用方式
from PIL import Image
import pytesseractdef recognize_png(image_path):imge = Image.open(image_path)text = pytesseract.image_to_string(imge,config='--psm 6 digits')return text.strip()print(recognize_png("img/captcha (1).png"))
驗證碼圖片
識別的結果
看起來效率比較低,后期試了ddddocr
,效率比這個高一點