Python?網(wǎng)易易盾滑塊驗(yàn)證功能的實(shí)現(xiàn)
記一次 網(wǎng)易易盾滑塊驗(yàn)證分析并通過
操作環(huán)境
- win10 、 mac
- Python3.9
- selenium、PIL、numpy、scipy、matplotlib
分析
網(wǎng)易易盾滑塊驗(yàn)證,就長下面這個樣子
具體驗(yàn)證原理有興趣的可自行查詢官方文檔:網(wǎng)易易盾開發(fā)文檔
話不多少,借助之前寫阿里云盾滑塊和極驗(yàn)滑塊的經(jīng)驗(yàn),直接上代碼,詳細(xì)可參考:[python3 破解 geetest(極驗(yàn))的滑塊驗(yàn)證碼功能]極驗(yàn)滑塊驗(yàn)證
解決方案
使用selenium請求url,并觸發(fā)滑塊驗(yàn)證
def open(self): # 初始化瀏覽器 wait = WebDriverWait(self.driver, 5) # 點(diǎn)擊對應(yīng)標(biāo)簽 self.driver.get(cfg.TEST_URL) button = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, cfg.HD_SELECOTR))) button.click() self.tc_item = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, cfg.TC_SELECOTR))) self.tc_item.click() # 得到背景和滑塊的item, 以及滑動按鈕 time.sleep(2) self.background_item = wait.until( EC.presence_of_element_located((By.CSS_SELECTOR, cfg.BG_SELECOTR)) ) self.slider_item = wait.until( EC.presence_of_element_located((By.CSS_SELECTOR, cfg.HK_SELECOTR)) ) self.slider_btn = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, cfg.HD_BTN))) self.offset = cfg.offset self.background_path = cfg.background_path self.slider_path = cfg.slider_path
獲取驗(yàn)證圖片并計算滑塊距離
def get_images(self): """ 獲取驗(yàn)證碼圖片 :return: 圖片的location信息 """ url = selenium_item.get_attribute("src") if url is not None: response = requests.get(url) with open(path, "wb") as f: f.write(response.content) img = Image.open(path).resize(size) img.save(path) else: class_name = selenium_item.get_attribute("class") js_cmd = ( 'return document.getElementsByClassName("%s")[0].toDataURL("image/png");' % class_name ) im_info = self.driver.execute_script(js_cmd) im_base64 = im_info.split(",")[1] im_bytes = base64.b64decode(im_base64) with open(path, "wb") as f: f.write(im_bytes) img = Image.open(path).resize(size) img.save(path) def compute_gap(self, array): """ 計算缺口偏移 """ grad = np.array(array > 0) h, w = grad.shape # img_show(grad) rows_sum = np.sum(grad, axis=1) cols_sum = np.sum(grad, axis=0) left, top, bottom = 0, 0, h # get the top index p = np.max(rows_sum) * 0.5 for i in range(h): if rows_sum[i] > p: top = i break for i in range(h - 1, -1, -1): if rows_sum[i] > p: bottom = i break p = np.max(cols_sum) * 0.5 for i in range(w): if cols_sum[i] > p: left = i break return top, bottom + 1, left
生成滑動軌跡
def get_tracks(distance): v = random.randint(0, 2) t = 1 tracks = [] cur = 0 mid = distance * 0.8 while cur < distance: if cur < mid: a = random.randint(2, 4) else: a = -random.randint(3, 5) s = v * t + 0.5 * a * t ** 2 cur += s v = v + a * t tracks.append(round(s)) tracks.append(distance - sum(tracks)) return tracks
滑動模塊
def move_to_gap(self, track): """滑動滑塊""" print('第一步,點(diǎn)擊滑動按鈕') slider = self.wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'geetest_slider_button'))) ActionChains(self.driver).click_and_hold(slider).perform() time.sleep(1) print('第二步,拖動元素') for track in track: ActionChains(self.driver).move_by_offset(xoffset=track, yoffset=0).perform() # 鼠標(biāo)移動到距離當(dāng)前位置(x,y) time.sleep(0.0001)
效果
資源下載
https://download.csdn.net/download/qq_38154948/85343666
到此這篇關(guān)于Python 網(wǎng)易易盾滑塊驗(yàn)證功能的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Python 易盾滑塊驗(yàn)證內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python采集圖片數(shù)據(jù)的實(shí)現(xiàn)示例
本文主要介紹了Python采集圖片數(shù)據(jù)的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-04-04如何將自己的python代碼發(fā)布在pip install給別人使用你知道嗎
這篇文章主要介紹了python如何發(fā)布自已的pip項(xiàng)目,方便大家學(xué)習(xí),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2021-08-08python中的字符轉(zhuǎn)運(yùn)算符、字符串處理方式
這篇文章主要介紹了python中的字符轉(zhuǎn)運(yùn)算符、字符串處理方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-07-07Win7下搭建python開發(fā)環(huán)境圖文教程(安裝Python、pip、解釋器)
這篇文章主要為大家分享了Win7下搭建python開發(fā)環(huán)境圖文教程,本文主要介紹了安裝Python、pip、解釋器的詳細(xì)步驟,感興趣的小伙伴們可以參考一下2016-05-05昨晚我用python幫隔壁小姐姐P證件照然后發(fā)現(xiàn)
大家好,我是Lex 喜歡欺負(fù)超人那個Lex 建議大家收藏哦,以后幫小姐姐P自拍,證件照,調(diào)尺寸,背景,摳圖,直接10行代碼搞定,瞬間高大上2021-08-08用Python爬取618當(dāng)天某東熱門商品銷量數(shù)據(jù),看看大家喜歡什么!
618購物節(jié),準(zhǔn)備分析一波購物節(jié)大家都喜歡買什么?本文以某東為例,Python爬取618活動的暢銷商品數(shù)據(jù),并進(jìn)行數(shù)據(jù)清洗,最后以可視化的方式從不同角度去了解暢銷商品中,名列前茅的商品是哪些?銷售數(shù)據(jù)如何?用戶好評如何?等等,需要的朋友可以參考下2021-06-06