最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python破解bilibili滑動(dòng)驗(yàn)證碼登錄功能

 更新時(shí)間:2019年09月11日 10:51:40   作者:邪惡馬克思  
這篇文章主要介紹了python破解bilibili滑動(dòng)驗(yàn)證碼登錄功能,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

地址:https://passport.bilibili.com/login

左圖事完整驗(yàn)證碼圖,右圖是有缺口的驗(yàn)證碼圖

                                                                    

步驟:

1.準(zhǔn)備bilibili賬號(hào)

2.工具:pycharm selenium chromedriver PIL

3.破解思路:

找到完整驗(yàn)證碼和有缺口的驗(yàn)證碼圖片,然后計(jì)算缺口坐標(biāo),再利用selenium移動(dòng)按鈕到指定位置,齊活

步驟代碼如下:

先導(dǎo)入需要的包和庫

from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
from urllib.request import urlretrieve
from bs4 import BeautifulSoup
from lxml.html import etree
import re,requests
from PIL import Image
from time import sleep
from .config import username,password
class Jiyan_test:
  def __init__(self):
    self.url='https://passport.bilibili.com/login'
    self.brower=webdriver.Chrome('chromedriver')
    self.wait=WebDriverWait(self.brower,20)#設(shè)置等待
 
  def login(self):
    self.brower.get(self.url)
    self.user=self.wait.until(EC.presence_of_element_located((By.ID,'login-username')))
    self.passwd=self.wait.until(EC.presence_of_element_located((By.ID,'login-passwd')))
    self.user.send_keys(username)
    self.passwd.send_keys(password)
  def get_images(self):#獲取驗(yàn)證碼圖片
    # print(self.brower.page_source)
    full_position=[]#完整散圖坐標(biāo)
    bg_position=[]#缺口散圖坐標(biāo)
    html=etree.HTML(self.brower.page_source)
    gt_cut_fullbg_slices=html.xpath('//div[@class="gt_cut_fullbg_slice"]/@style')
    full_slice_url=re.findall('url\(\"(.*)\"\);',gt_cut_fullbg_slices[0])[0].replace('webp','jpg')
    gt_cut_bg_slices = html.xpath('//div[@class="gt_cut_bg_slice"]/@style')
    bg_slice_url = re.findall('url\(\"(.*)\"\);', gt_cut_bg_slices[0])[0].replace('webp', 'jpg')
    print(gt_cut_fullbg_slices)
    for i in gt_cut_fullbg_slices:
      position=re.findall('background-position: (.*);',i)[0].replace('px','').split(' ')
      position=[int(i) for i in position]
      full_position.append(position)
    for i in gt_cut_fullbg_slices:
      position = re.findall('background-position: (.*);', i)[0].replace('px','').split(' ')
      position=[int(i) for i in position]
      bg_position.append(position)
    print(full_position)
    print(bg_position)
    print(full_slice_url)
    print(bg_slice_url)
    full_pic_data=requests.get(full_slice_url).content
    bg_pic_data=requests.get(bg_slice_url).content
    with open('image/full_pic.jpg','wb') as f:
      f.write(full_pic_data)
    with open('image/bg_pic.jpg', 'wb') as f:
      f.write(bg_pic_data)
    full_image=Image.open('image/full_pic.jpg')
    bg_image=Image.open('image/bg_pic.jpg')
    return full_image,bg_image,full_position,bg_position

分割圖片 

def pic_cut(self,file,position):#分割圖片
    first_line_pic=[]
    second_line_pic=[]
    # full_image, bg_image, full_position, bg_position=self.get_images()
    for p in position:
      if p[1]==-58:
        first_line_pic.append(file.crop((abs(p[0]),58,abs(p[0])+10,166)))
      if p[1]==0:
        second_line_pic.append(file.crop((abs(p[0]),0,abs(p[0])+10,58)))
    print(first_line_pic)
    print(second_line_pic)
    return first_line_pic,second_line_pic

合并圖片

   

 def merge_pics_new(self,first_line_pic,second_line_pic,file_name):
    #新建圖片
    image=Image.new('RGB',(260,116))
    offset=0#設(shè)置偏移量
    #拼接第一行
    for i in first_line_pic:
      image.paste(i,(offset,0))
      offset+=i.size[0]
    offset_x=0
    #拼接第二行
    for j in second_line_pic:
      image.paste(j,(offset_x,58))
      offset_x+=j.size[0]
    image.save('image/'+file_name)#合成完整圖片
 
  def merge_pics(self):#合并圖片
    #先割切亂碼圖片
    full_image, bg_image, full_position, bg_position=self.get_images()
    first_line_pic, second_line_pic=self.pic_cut(full_image,full_position)
    self.merge_pics_new(first_line_pic, second_line_pic,'full_new_pic.jpg')
    first_line_pic, second_line_pic = self.pic_cut(bg_image, bg_position)
    self.merge_pics_new(first_line_pic, second_line_pic, 'bg_new_pic.jpg')

再判斷圖片是否一樣

  def check_pics_is_same(self,bg_image,full_image,x,y):#判斷圖片是否一樣
    bg_pixel=bg_image.getpixel((x,y))
    full_pixel=full_image.getpixel((x,y))
    for i in range(0,3):
      if abs(bg_pixel[i]-full_pixel[i])>=50:
        return False
      else:
        return True

計(jì)算滑塊距離

   

def reckon_distance2(self):#計(jì)算滑塊
    try:
      full_image = Image.open('image/full_new_pic.jpg')
      bg_image = Image.open('image/bg_new_pic.jpg')
      for i in range(0,full_image.size[0]):
        for j in range(0,full_image.size[1]):
          if not self.check_pics_is_same(bg_image,full_image,i,j):
            return i
    except Exception:
      print('圖片讀取失敗')

計(jì)算運(yùn)動(dòng)軌跡

    

def reckon_trail(self):#計(jì)算運(yùn)動(dòng)軌跡
    print('計(jì)算運(yùn)動(dòng)軌跡')
    track=[]
    distance=self.reckon_distance2()
    distance=int(distance)-7#矯正值
    print('缺口坐標(biāo)',distance)
    fast_distance=distance*(4/5)
    start,v0,t=0,0,0.2
    while start<distance:
      if start<fast_distance:#加速狀態(tài)
        a=1.5#加速
      else:
        a=-3#減速
      #數(shù)學(xué)公式 s=v0*t+1/2 v*t平方
      move=v0*t+1/2*a*t*t
      #當(dāng)前速度
      v=v0+a*t
      #重置粗速度
      v0=v
      #重置起始位置
      start+=move
      track.append(round(move))
    return track

 

模擬拖動(dòng)

def move_block(self):# 模擬拖動(dòng)滑塊
    print('開始模擬')
    track=self.reckon_trail()
    #找尋滑塊標(biāo)簽
    slider=self.wait.until(EC.presence_of_element_located((By.CLASS_NAME,'gt_slider_knob')))
    ActionChains(self.brower).click_and_hold(slider).perform()#執(zhí)行
    for x in track:
      ActionChains(self.brower).move_by_offset(xoffset=x,yoffset=0).perform()
    sleep(0.4)
    ActionChains(self.brower).release().perform()#釋放滑塊
 
if __name__ == '__main__':
  c=Jiyan_test()
  c.login()
  c.merge_pics()
  c.move_block()

測(cè)試運(yùn)行正常,偶爾有對(duì)不準(zhǔn)的現(xiàn)象,需要調(diào)整distance的值

總結(jié)

以上所述是小編給大家介紹的python破解bilibili滑動(dòng)驗(yàn)證碼登錄功能,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!

相關(guān)文章

  • 一篇文章了解Python中常見的序列化操作

    一篇文章了解Python中常見的序列化操作

    這篇文章主要給大家介紹了軟玉Python中常見的序列化操作的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Python具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06
  • 淺談Python type的使用

    淺談Python type的使用

    今天小編就為大家分享一篇淺談Python type的使用,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2019-11-11
  • 使用PyQt5實(shí)現(xiàn)一個(gè)鼠標(biāo)連點(diǎn)器

    使用PyQt5實(shí)現(xiàn)一個(gè)鼠標(biāo)連點(diǎn)器

    這篇文章主要為大家詳細(xì)介紹了如何使用PyQt5實(shí)現(xiàn)一個(gè)鼠標(biāo)連點(diǎn)器,從而對(duì)QVBoxLayout、QHBoxLayout和QStackedWidget進(jìn)行一個(gè)回顧復(fù)習(xí),需要的可以參考一下
    2023-12-12
  • Python如何在Word中查找并替換文本

    Python如何在Word中查找并替換文本

    這篇文章主要為大家詳細(xì)介紹了Python在Word中實(shí)現(xiàn)查找并替換文本的相關(guān)方法,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2025-03-03
  • python 寫一個(gè)文件分發(fā)小程序

    python 寫一個(gè)文件分發(fā)小程序

    這篇文章主要介紹了python 寫一個(gè)文件分發(fā)小程序,幫助大家更好的理解和學(xué)習(xí)python,感興趣的朋友可以了解下
    2020-12-12
  • Python實(shí)現(xiàn)二維曲線擬合的方法

    Python實(shí)現(xiàn)二維曲線擬合的方法

    今天小編就為大家分享一篇Python實(shí)現(xiàn)二維曲線擬合的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-12-12
  • PyQt5 在QListWidget自定義Item的操作

    PyQt5 在QListWidget自定義Item的操作

    這篇文章主要介紹了PyQt5 在QListWidget自定義Item的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2021-03-03
  • PyTorch計(jì)算損失函數(shù)對(duì)模型參數(shù)的Hessian矩陣示例

    PyTorch計(jì)算損失函數(shù)對(duì)模型參數(shù)的Hessian矩陣示例

    這篇文章主要為大家介紹了PyTorch計(jì)算損失函數(shù)對(duì)模型參數(shù)的Hessian矩陣的示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-05-05
  • Python中的取整、取余運(yùn)算方法

    Python中的取整、取余運(yùn)算方法

    數(shù)據(jù)處理是編程中不可避免的,很多時(shí)候都需要根據(jù)需求把獲取到的數(shù)據(jù)進(jìn)行處理,取整則是最基本的數(shù)據(jù)處理。取整的方式則包括向下取整、四舍五入、向上取整等等,這篇文章主要介紹了Python中的取整、取余運(yùn)算,需要的朋友可以參考下
    2022-11-11
  • 樹莓派極簡(jiǎn)安裝OpenCv的方法步驟

    樹莓派極簡(jiǎn)安裝OpenCv的方法步驟

    這篇文章主要介紹了樹莓派極簡(jiǎn)安裝OpenCv的方法步驟,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-10-10

最新評(píng)論

曲阜市| 分宜县| 怀来县| 云安县| 孟村| 中阳县| 临夏县| 栾川县| 九江市| 海林市| 台前县| 榕江县| 新闻| 读书| 嘉鱼县| 新源县| 木里| 泌阳县| 长葛市| 辰溪县| 天津市| 龙州县| 上栗县| 正镶白旗| 平乐县| 元氏县| 麻江县| 汝城县| 西畴县| 博罗县| 合川市| 临朐县| 闽清县| 绥德县| 驻马店市| 九江市| 浪卡子县| 东明县| 衡东县| 准格尔旗| 镇远县|