from DrissionPage import ChromiumPage,ChromiumOptions
from DrissionPage.common import Actions
from DownloadKit import DownloadKit
import cv2
import time
import re
co = ChromiumOptions()
co.set_argument('--guest')
def get_pos(imageSrc):
image = cv2.imread(imageSrc)
blurred = cv2.GaussianBlur(image, (5, 5), 0, 0)
canny = cv2.Canny(blurred, 0, 100)
contours, hierarchy = cv2.findContours(canny, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
for contour in contours:
area = cv2.contourArea(contour)
length = cv2.arcLength(contour, True)
if 5025 < area < 7225 and 300 < length < 380:
x, y, w, h = cv2.boundingRect(contour)
print("计算出目标区域的坐标及宽高:", x, y, w, h)
cv2.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), 2)
cv2.imwrite("111.jpg", image)
return x,w,h
return 0
page = ChromiumPage(co)
page.get('https://xxx.xxx.com/login')
page.ele('@placeholder=邮箱或手机号码').input(vals='xxxx@demo.com',clear=True)
page.ele('@placeholder=密码').input(vals='123456',clear=True)
page.ele('xpath://*[@id="app"]/div/div[1]/div/div[1]/div/div[2]/div/main/form/div[3]/div[1]/div/button').click()
time.sleep(1)
iframe = page('#tcaptcha_iframe_dy')
iframe = page.get_frame(iframe)
ele1 = iframe('#slideBg')
img_url = ele1.attr('style')
urls = re.findall(r'url\("([^"]+)"\)', img_url)
d = DownloadKit()
d.set.if_file_exists.overwrite()
d(file_url=urls[0],rename='1.jpg')
time.sleep(2)
x = get_pos('1.jpg')
x = x-60
newDis = int(x * 340 / 672 )
ac = Actions(iframe)
ac.move_to('.tc-fg-item tc-slider-normal').hold().move(newDis,0,0.5).release('.tc-fg-item tc-slider-normal')
page.ele('.__button-dark-enagr0-lmmp n-button n-button--primary-type n-button--medium-type n-button--block').click()