selenium截取驗證碼圖片


# 截取驗證碼圖片
from PIL import Image
driver.save_screenshot('bdbutton.png')
element = driver.find_element_by_xpath('//*[@id="nc_1_clickCaptcha"]/div[2]/img')    #找到驗證碼圖片
print(element.location)                # 打印元素坐標
print(element.size)                    # 打印元素大小
left = element.location['x']
top = element.location['y']
right = element.location['x'] + element.size['width']
bottom = element.location['y'] + element.size['height']

im = Image.open('bdbutton.png')
im = im.crop((left, top, right, bottom))
im.save('bdbutton.png')                          # 將得到的圖片保存在本地

 


免責聲明!

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



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