Python:3.7.7
PyCharm:2019.2.6
Chrome浏览器:89.0.4389.114
创建三个python项目文件,分别存放主代码、对接第三方代码和账号密码
import base64
import json
import requests
def base64_api(uname, pwd, img,img2):
with open(img, 'rb') as f:
base64_data = base64.b64encode(f.read())
b64 = base64_data.decode()
with open(img2,'rb') as t:
base64_data2 = base64.b64encode(t.read())
b642 = base64_data2.decode()
data = {"username": uname, "password": pwd, "image": b64,"imageback": b642,"typeid": '18'}
result = json.loads(requests.post("http://api.ttshitu.com/imageXYPlus", json=data).text)
if result['success']:
return result["data"]["result"]
else:
return result["message"]
USER_NAME = '******'
USER_PASSWD = '*******'
KSB_NAME = '****'
KSB_PASSWD = '******'
from selenium import webdriver # 导入浏览器
from PIL import Image #用来剪切图像
from selenium.webdriver import ActionChains # 导入动作链模块
from ksb import base64_api
from paswd import USER_NAME,USER_PASSWD,KSB_PASSWD,KSB_NAME
import time
import requests
import random
headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'
}
url = 'https://register.ccopyright.com.cn/login.html'
down_load_path='E:\\下载的music\\'
a = random.randrange(1, 100, 3)
b = random.randrange(1, 100, 2)
class login_addr():
def __init__(self,url):
self.url = url
def log_in(self):
driver = webdriver.Chrome(executable_path='chromedriver.exe')
driver.get(self.url)
driver.implicitly_wait(20)
# 最大化浏览器
driver.maximize_window()
# 选择登陆类型
search_type = driver.find_element_by_xpath('/html/body/div[2]/div[2]/div/div[2]/div/div[1]/ul/li[2]')
search_type.click()
# 定位用户名输入框
user_input = driver.find_element_by_xpath('/html/body/div[2]/div[2]/div/div[2]/div/div[3]/div[1]/div[2]/div[1]/div/div[2]/div[2]/div/input')
# 输入用户名称
user_input.send_keys(USER_NAME)
user_passwd = driver.find_element_by_xpath('/html/body/div[2]/div[2]/div/div[2]/div/div[3]/div[1]/div[2]/div[1]/div/div[3]/div[2]/div/input') # 定位密码框
user_passwd.send_keys(USER_PASSWD) # 输入密码
time.sleep(2)
driver.find_element_by_xpath('/html/body/div[2]/div[2]/div/div[2]/div/div[3]/div[2]/div[2]/button').click() # 点击登录
time.sleep(2)
image_label_bcg = driver.find_element_by_xpath('/html/body/div[3]/div[2]/div/div/div[2]/div/div[1]/div/div[1]/img[1]').get_attribute('src') # 定位滑块背景图,获取src元素(图片的访问地址)
rel_image_label_bcg=requests.get(url=image_label_bcg,headers=headers).content # 访问图片
# image_label_bcg.screenshot('bcg.png') # 截取图片
image_log = driver.find_element_by_xpath('/html/body/div[3]/div[2]/div/div/div[2]/div/div[1]/div/div[1]/img[2]').get_attribute('src') # 定位滑块位置,获取src元素
log_path = driver.find_element_by_xpath('/html/body/div[3]/div[2]/div/div/div[2]/div/div[1]/div/div[1]/img[2]') # 定位滑块位置
rel_image_log=requests.get(url=image_log,headers=headers).content # 访问滑块图片
# image_log.screenshot('log.png') # 截取滑块
## 保存背景图和滑块图
with open(str(a)+'.jpg','wb') as f:
f.write(rel_image_label_bcg)
with open(str(b)+'.png','wb') as t:
t.write(rel_image_log)
c = base64_api(KSB_NAME, KSB_PASSWD, str(b)+'.png',str(a)+'.jpg') #对接第三方破解平台
print(c)
x = c.split(',')[0] # 获取x坐标
y = c.split(',')[1] # 获取y坐标
action_chains = ActionChains(driver)
# action_chains.click_and_hold(log_path) # 模仿鼠标点击定位的元素
# action_chains.pause(2) #暂停2秒
action_chains.drag_and_drop_by_offset(log_path, int(x)+5,0) # 鼠标滑动定位元素到指定坐标后释放鼠标
# action_chains.release() #在定位元素处释放鼠标左键
action_chains.perform() # 执行整个动作链
# input()
driver.quit() # 退出浏览器
if __name__ == '__main__':
login_addr(url).log_in()