python+selenium進行簡單驗證碼獲取


# _*_ coding:utf-8 _*_
from PIL import Image
from selenium import webdriver
import pytesseract
import time

url = 'https://ec.ayyywl.com/login'
driver = webdriver.Chrome()
driver.maximize_window() # 將瀏覽器最大化
driver.get(url)
# 截取當前網頁並放到E盤下命名為printscreen,該網頁有我們需要的驗證碼


driver.save_screenshot('F:\\printscreen.png')
imgelement = driver.find_element_by_xpath('//*[@id="root"]/div/div/div/div/div/div/div[2]/div/form/div[3]/div/div/div[2]/img') # 定位驗證碼
location = imgelement.location # 獲取驗證碼x,y軸坐標

size = imgelement.size # 獲取驗證碼的長寬

rangle = (int(location['x']), int(location['y']), int(location['x'] + size['width']),
int(location['y'] + size['height'])) # 寫成我們需要截取的位置坐標

i = Image.open("F:\\printscreen.png") # 打開截圖
frame4 = i.crop(rangle) # 使用Image的crop函數,從截圖中再次截取我們需要的區域
frame4.save('F:\\save.png') # 保存我們接下來的驗證碼圖片 進行打碼time
#這樣獲取到的圖片就是驗證碼了。。不過是最簡單的那種還需要進行調整




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM