1. 程式人生 > 程式設計 >Python 點選指定位置驗證碼破解的實現程式碼

Python 點選指定位置驗證碼破解的實現程式碼

思路:

建立瀏覽器驅動物件

載入登入頁面

等待頁面載入完畢

切換到使用者名稱和密碼登入模式

輸入手機號,注意此處需要等待並獲取輸入框

輸入密碼

點選驗證按鈕

獲取彈出驗證圖片

使用超級鷹打碼平臺識別圖形的座標

獲取到座標資訊,x,y座標分別除以2; 由於電腦解析度太過了,是原來的兩倍,如果是普通解析度可以除以2,直接用就可以了.

把滑鼠移動到,座標點的位置進行點選

點選登入按鈕

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import ActionChains

import time
# 匯入超級鷹
from chaojiying import chaojiying
#根據系統,可能截圖不成功,需要使用無頭瀏覽,mac系統可以不設定
options=webdriver.ChromeOptions()
options.headless=True

driver=webdriver.Chrome(options=potions)
driver.get('http://www.zhaopingou.com/signin')


driver.find_element_by_class_name('li02').click()
wait=WebDriverWait(driver,20,0.5)
# 賬號登入
login_phone=wait.until(EC.visibility_of_element_located((By.ID,'pwd_login_phone')))
login_phone.send_keys('17724035140')
# 密碼
driver.find_element_by_id('form_login_password').send_keys('961831740hzll')
# 點選獲取圖片
captcha = wait.until(EC.visibility_of_element_located((By.XPATH,'//div[@class="phone_login_pwd"]//iframe[starts-with(@id,"captcha_widget")]')))
captcha.click()
# 點選
# 儲存圖片(可以不儲存)
captcha_element = wait.until(EC.visibility_of_element_located((By.XPATH,'//body[@class="graybc"]//iframe[starts-with(@id,"captcha_frame")]')))
captcha_element.screenshot('zhaopingou.png')

# 將圖片轉換為二進位制
bytes_img=captcha_element.screenshot_as_png
# print(bytes_img)

result=chaojiying.post_pic(bytes_img,'9101')
x,y=result['pic_str'].split(',')
print(x,y)
x=int(x)
y=int(y)
# ActionChains(driver).move_to_element_with_offset(bytes_img,y).click().perform()
ActionChains(driver).move_to_element_with_offset(captcha_element,y).click().perform()
time.sleep(2)
driver.find_element_by_id('free_login_btn').click()

print(driver.window_handles)
driver.switch_to.window(driver.window_handles[0])
# time.sleep(5)
driver.quit()

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。