Python 最新版破解滑块验证码自动登录QQ空间
本節所講內容:
Selenium+Python環境搭建及配置
滑塊驗證碼步驟分解
QQ空間破解滑塊驗證碼登錄(全部代碼請看最后)
1.1? selenium 介紹
1.2 ?selenium+Python環境配置
前提條件:已安裝好Python開發環境(python3.7.2),這是最基本的呦~
安裝步驟:
1.??安裝selenium:pip install selenium
2.? 安裝webdriver
各大瀏覽器webdriver地址可參見:https://docs.seleniumhq.org/download/
Firefox:https://github.com/mozilla/geckodriver/releases/
Chrome:https://sites.google.com/a/chromium.org/chromedriver/?或者
http://chromedriver.storage.googleapis.com/index.html
IE:http://selenium-release.storage.googleapis.com/index.html
? 注:webdriver需要和對應的瀏覽器版本以及selenium版本對應
| Webdriver版本 | 支持的Chrome版本 |
| v2.41 | v67-69 |
| v2.40 | v66-68 |
| v2.39 | v66-68 |
| v2.38 | v65-67 |
| v2.37 | v64-66 |
| v2.36 | v63-65 |
| v2.35 | v62-64 |
| v2.34 | v61-63 |
3.? webdriver安裝路徑
Win:復制webdriver到Python安裝目錄下或者在path中配置下路徑(方便python能快速尋找)
? ??
2.? 滑塊驗證碼步驟分解
第一步:訪問QQ空間登錄網址,定位iframe登錄標簽,點擊賬號密碼
代碼實現:
driver = webdriver.Chrome() driver.set_window_position(900, 10) driver.maximize_window() driver.get(url) #切換frame driver.switch_to.frame('login_frame') #點擊 driver.find_element_by_id("switcher_plogin").click()第二步:跳轉到輸入界面,然后清空每個輸入框的數據然后在點擊登錄
代碼實現:
# 輸入用戶名和密碼 driver.find_element_by_id('u').clear() driver.find_element_by_id('u').send_keys('3403073998') driver.find_element_by_id('p').clear() driver.find_element_by_id('p').send_keys('family521@#!') sleep(1)# 點擊登錄 driver.find_element_by_id('login_button').click() sleep(5)第三步:再次定位到iframe按鈕操作并進行拖拽,距離我們保持固定180,圖片讓它更換底板圖片
在這個地方需要注意點的是我們并沒有對滑塊移動的距離進行確定,
只是寫一個distances=180這個固定的距離,
當然在這個拉取的過程中每次拉取也有可能失敗,這是正常現象,請各位拿到代碼后運行下
代碼實現:
# 切換iframe try:iframe = driver.find_element_by_xpath('//iframe') except Exception as e:pass sleep(2)?? # 等待資源加載driver.switch_to.frame(iframe)# 等待圖片加載出來 WebDriverWait(driver, 5, 0.5).until(EC.presence_of_element_located((By.ID, "tcaptcha_drag_button")) ) try:button = driver.find_element_by_id('tcaptcha_drag_button') except Exception as e:passsleep(1) # 開始拖動 perform()用來執行ActionChains中存儲的行為 #distance 代表的是滑塊移動的距離,我們這里直接寫死 distance = 180 times = 0 while True:try:action = ActionChains(driver)#點擊鼠標并進行拖拽action.click_and_hold(button).perform()# 清除之前的actionaction.reset_actions()#模擬軌跡方程track = get_track(distance)#開始模擬拖拽for i in track:#y軸不偏移,x軸持續滑動action.move_by_offset(xoffset=i, yoffset=0).perform()action.reset_actions()sleep(0.5)#釋放鼠標action.release().perform()sleep(5)times += 1print('這是第{}次'.format(times))except:print('登錄成功')break軌跡方程:(為了模仿人為的動作,防止整理)
def get_track(distance):"""根據偏移量獲取移動軌跡:param distance: 偏移量:return: 移動軌跡"""# 移動軌跡track = []# 當前位移current = 0# 減速閾值mid = distance * 4 / 5# 計算間隔t = 1# 初速度# v = 0v = 0while current < distance:if current < mid:# 加速度為正2# a_b = 8a = 10else:# 加速度為負3a = -3# 初速度v0v0 = v# 當前速度v = v0 + atv = v0 + a * t# 移動距離x = v0t + 1/2 * a_b * t^2move = v0 * t + 1 / 2 * a * t * t# 當前位移current += move# 加入軌跡track.append(round(move))return track3.? QQ空間破解滑塊模擬登錄全部代碼
#!/usr/bin/python # -*- coding: utf-8 -*- # @Time??? : 2020/2/21 21:18 # @Author? : Xuegod Teacher For # @File??? : qq空間.py from time import sleep from selenium import webdriver from selenium.webdriver import ActionChains from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.wait import WebDriverWaiturl = 'https://i.qq.com'def get_track(distance):"""根據偏移量獲取移動軌跡:param distance: 偏移量:return: 移動軌跡"""# 移動軌跡track = []# 當前位移current = 0# 減速閾值mid = distance * 4 / 5# 計算間隔t = 1# 初速度# v = 0v = 0while current < distance:if current < mid:# 加速度為正2# a_b = 8a = 10else:# 加速度為負3a = -3# 初速度v0v0 = v# 當前速度v = v0 + atv = v0 + a * t# 移動距離x = v0t + 1/2 * a_b * t^2move = v0 * t + 1 / 2 * a * t * t# 當前位移current += move# 加入軌跡track.append(round(move))return trackdef main():driver = webdriver.Chrome()driver.set_window_position(900, 10)driver.maximize_window()driver.get(url)driver.switch_to.frame('login_frame')driver.find_element_by_id("switcher_plogin").click()sleep(1)# 輸入用戶名和密碼driver.find_element_by_id('u').clear()driver.find_element_by_id('u').send_keys('你的QQ賬號')driver.find_element_by_id('p').clear()driver.find_element_by_id('p').send_keys('你的QQ密碼')sleep(1)# 點擊登錄driver.find_element_by_id('login_button').click()sleep(5)# 切換iframetry:iframe = driver.find_element_by_xpath('//iframe')except Exception as e:passsleep(2)?? # 等待資源加載driver.switch_to.frame(iframe)# 等待圖片加載出來WebDriverWait(driver, 5, 0.5).until(EC.presence_of_element_located((By.ID, "tcaptcha_drag_button")))try:button = driver.find_element_by_id('tcaptcha_drag_button')except Exception as e:passsleep(1)# 開始拖動 perform()用來執行ActionChains中存儲的行為distance = 180times = 0while True:try:action = ActionChains(driver)#點擊鼠標并進行拖拽action.click_and_hold(button).perform()# 清除之前的actionaction.reset_actions()#模擬軌跡方程track = get_track(distance)#開始模擬拖拽for i in track:#y軸不偏移,x軸持續滑動action.move_by_offset(xoffset=i, yoffset=0).perform()action.reset_actions()sleep(0.5)#釋放鼠標action.release().perform()sleep(5)times += 1print('這是第{}次'.format(times))except:print('登錄成功')breakprint(driver.title)sleep(2)driver.quit()print("finish~~")if __name__ == '__main__':main()?
總結
以上是生活随笔為你收集整理的Python 最新版破解滑块验证码自动登录QQ空间的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数字图像处理技术
- 下一篇: 用友python模块_最新用友NC6.5