日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用打码平台登录B站

發布時間:2023/12/15 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用打码平台登录B站 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

B站登錄需要用到圖片點坐標點選類型的驗證碼驗證,使用傳統的OCR技術解決起來比較棘手,因此借助于第三方打碼平臺,可以快速實現這一功能。

  • 創建項目【使用打碼平臺登錄B站】,新建python文件【bili.py】【img_api.py】【accounts.py】
  • 進入【accounts.py】,定義你的打碼平臺和B站賬號以及密碼
"""快識別賬號密碼""" KUAI_USER = '你的賬號' KUAI_PASS = '你的密碼'"""B站賬號密碼""" BILI_USER = '你的賬號' BILI_PASS = '你的密碼'
  • 進入【img_api.py】文件,進入打碼平臺開發文檔的python接口(上面有提示,不打廣告),把開發文檔復制到【img_api.py】
import base64 import json import requests # 一、圖片文字類型(默認 3 數英混合): # 1 : 純數字 # 1001:純數字2 # 2 : 純英文 # 1002:純英文2 # 3 : 數英混合 # 1003:數英混合2 # 4 : 閃動GIF # 7 : 無感學習(獨家) # 11 : 計算題 # 1005: 快速計算題 # 16 : 漢字 # 32 : 通用文字識別(證件、單據) # 66: 問答題 # 49 :recaptcha圖片識別 # 二、圖片旋轉角度類型: # 29 : 旋轉類型 # # 三、圖片坐標點選類型: # 19 : 1個坐標 # 20 : 3個坐標 # 21 : 3 ~ 5個坐標 # 22 : 5 ~ 8個坐標 # 27 : 1 ~ 4個坐標 # 48 : 軌跡類型 # # 四、缺口識別 # 18 : 缺口識別(需要2張圖 一張目標圖一張缺口圖) # 33 : 單缺口識別(返回X軸坐標 只需要1張圖) # 五、拼圖識別 # 53:拼圖識別 def base64_api(uname, pwd, img, typeid):with open(img, 'rb') as f:base64_data = base64.b64encode(f.read())b64 = base64_data.decode()data = {"username": uname, "password": pwd, "typeid": typeid, "image": b64}result = json.loads(requests.post("http://api.ttshitu.com/predict", json=data).text)if result['success']:return result["data"]["result"]else:return result["message"]return ""if __name__ == "__main__":img_path = "C:/Users/Administrator/Desktop/file.jpg"result = base64_api(uname='你的賬號', pwd='你的密碼', img=img_path, typeid=3)print(result)
  • 重寫【img_api.py】文件
import base64 from accounts import KUAI_USER, KUAI_PASS # accounts.py中導入你定義的打碼平臺賬號和密碼變量 import requestsdef base64_api(img):# 定義一個函數, 把用戶名,密碼 和圖片路徑傳進去with open(img, 'rb') as f: # 打開請求到的驗證碼圖片base64_data = base64.b64encode(f.read()).decode() # 讀取驗證碼圖片并且轉換成字符串類型data = {"username": KUAI_USER , "password": KUAI_PASS, "typeid": 21, "image": base64_data} # 用戶名和密碼導入,typeid是根據開發文檔查到的對應接口數字(B站驗證碼為圖片坐標點選類型), image是圖片字符串數據result = requests.post("http://api.ttshitu.com/predict", data=data).json() # 攜帶data參數,發送post請求,返回json數據if result['success']:return result["data"]["result"]else:return result["message"]if __name__ == "__main__":img_path = "yzm.png" # 相對路徑,由【bili.py】保存在項目文件下result = base64_api(img=img_path) # 把img_path傳遞進去,調用base64_api函數print(result)
  • 進入谷歌瀏覽器,搜索欄輸入:chrome://version 查看瀏覽器版本

  • 進入(https://registry.npmmirror.com/binary.html?path=chromedriver/)查找谷歌瀏覽器對應的版本號,下載下來并解壓,放到項目路徑下面

  • 進入【bili.py】,編寫主程序
import time from selenium.webdriver.common.by import By from accounts import BILI_USER, BILI_PASS from selenium import webdriver from selenium.webdriver import ActionChains from img_api import base64_apidriver = webdriver.Chrome() # 實例化瀏覽器驅動 driver.get('https://passport.bilibili.com/login') # 發送請求 driver.implicitly_wait(10) # 隱式等待10秒 driver.maximize_window() # 最大化瀏覽器窗口"""找用戶名和密碼框, 輸入數據""" username_input = driver.find_element(By.CSS_SELECTOR, '#login-username') # 使用css語法定位用戶名輸入框 username_input.click() # 點擊賬號輸入框 time.sleep(0.5) # 強制等待0.5秒 username_input.send_keys(BILI_USER) # 傳入賬號 time.sleep(0.5) # 強制等待0.5秒password_input = driver.find_element(By.CSS_SELECTOR, '#login-passwd') # 使用css語法定位密碼輸入框 password_input.click() # 點擊密碼輸入框 time.sleep(0.5) password_input.send_keys(BILI_PASS) # 傳入密碼 time.sleep(0.5)"""點擊登錄按鈕""" time.sleep(0.5) driver.find_element(By.CSS_SELECTOR, '.btn.btn-login').click() # 使用css語法定位登錄按鈕并點擊 time.sleep(2)# 找驗證碼對應的標簽 img_label = driver.find_element(By.CSS_SELECTOR, '.geetest_holder.geetest_silver') # 點擊登錄后跳轉到驗證碼驗證界面,使用css語法定位到驗證碼標簽對象"""直接根據標簽元素保存圖片""" time.sleep(4) # 保存驗證碼前一定要加強制等待 img_label.screenshot('yzm.png') # 截取驗證碼圖片 time.sleep(4) print('正在保存驗證碼...')"""識別圖驗證碼""" code_result_list = base64_api('yzm.png') # 調用【img_api.py】,返回的數據是X,Y 坐標值 print('驗證碼識別結果為:', code_result_list) # 113,79|197,147result_list = code_result_list.split('|') # ['113,79', '197,147'],轉換成列表for result in result_list:x = result.split(',')[0] # 根據列表索引取出 X 坐標值,是str類型y = result.split(',')[1] # 根據列表索引取出 Y 坐標值,是str類型# ActionChains 鼠標動作鏈對象# move_to_element_with_offset 根據元素執行點擊操作# perform() 執行動作鏈ActionChains(driver).move_to_element_with_offset(img_label, int(x), int(y)).click().perform()time.sleep(5) """點擊確認""" driver.find_element(By.CSS_SELECTOR, '.geetest_commit_tip').click()input() driver.quit()
  • 運行【bili.py】
  • 跳轉到短信驗證碼登錄頁面,證明打碼成功

總結

以上是生活随笔為你收集整理的使用打码平台登录B站的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。