程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Using python, selenium and super eagle to realize automatic login of station B

編輯:Python

        python Xiaobai wrote the program by looking up the data , If there are defects and deficiencies, please correct them ! Combined with the selenium Anti identification . It adopts the method of simulating user login ( Not cookie) , The verification code part adopts super Eagle identification interface , Return coordinates , Then use the action chain to click the specified text , Through robot detection .

# Author:Yuan Jinmin
# -*- coding = utf-8 -*-
# @Time :2022/2/16 14:47
# @Author:YJM
# @Site :
# @File :seleniumDemo.py
# @Software: IntelliJ IDEA
import time
from selenium.webdriver.common.action_chains import ActionChains
from selenium import webdriver
# !!! You need to import super Eagle by yourself
if __name__ == '__main__':
url = 'https://passport.bilibili.com/login'
username = 'B Station account ' # !!! To change it to your own
password = ' password '
# hide webdriver Method , no need , The mobile phone verification code interface will appear
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-automation']) # Set to developer mode
options.add_argument("--disable-blink-features=AutomationControlled")
driver = webdriver.Chrome(
executable_path='!!! Change to your own Google drive location '
, options=options)
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument",{
'source': '''Object.defineProperty(navigator, 'webdriver', { get: () =>undefined })'''})
# # Maximization window
# driver.maximize_window()
driver.get(url=url)
time.sleep(3)
# Pass in the user name
driver.find_element_by_xpath('//*[@id="login-username"]').send_keys(username)
time.sleep(0.5)
# Pass in the password
driver.find_element_by_xpath('//*[@id="login-passwd"]').send_keys(password)
time.sleep(0.5)
# Click the login button
driver.find_element_by_xpath('//*[@id="geetest-wrap"]/div/div[5]/a[1]').click()
# Capture captcha image
time.sleep(2)
code_img_element = driver.find_element_by_xpath('/html/body/div[2]/div[2]')
code_img = code_img_element.screenshot('code.png') # With one
# # Get the coordinates of the upper left corner of the verification code picture box
# location = code_img.location
# print('code_img location:', location)
# # Length and width of verification code
# size = code_img.size
# print('code_img size:', size)
# Give it to the super Eagle identification verification code , You need to guide the package by yourself , Sample downloads are available on the official website
# Call the super Eagle platform interface identification verification code
print(' Identifying verification code ...')
chaojiying = chaojiying.Chaojiying_Client(' Super Eagle username ', ' password ',
' Software ID')
    # !!! To change it to your own user name , password , Software ID , User center >> Software ID Generate a replacement 96001
im = open('code.png', 'rb').read() # Local image file path To replace a.jpg Sometimes WIN The system needs //
answer = chaojiying.PostPic(im, 9004) # 9004 Select multiple coordinates , return 1~4 A coordinate , Such as :x1,y1|x2,y2|x3,y3 25
# print(answer) # 1902 Verification code type Official website >> The price system 3.4+ edition print After ()
# Output example :
# {'err_no': 0, 'err_str': 'OK', 'pic_id': '9168012087860700001', 'pic_str': '7261', 'md5': 'bf67edb09a6d203c34ac591c824d995b'}
# Get the verification code
code = answer['pic_str']
# coordinate
coordinate = [xy.split(sep=',') for xy in code.split(sep='|')] # [['1', '2'], ['3', '4'], ['1', '2'], ['3', '4']]
print(' Parsing the verification code succeeded ! Coordinate for :', coordinate)
# Traverse coordinate list , Use the action chain to click on each coordinate in the list , Achieve the purpose of clicking the verification code
for xy in coordinate:
x = xy[0]
y = xy[1]
ActionChains(driver).move_to_element_with_offset(code_img_element, x, y).click().perform()
time.sleep(0.5)
driver.find_element_by_xpath('/html/body/div[2]/div[2]/div[6]/div/div/div[3]/a').click()
input(' Please enter any character to end the program !')


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved