首页 > 编程语言 >AI生成的程序-自动点击文字定位验证码

AI生成的程序-自动点击文字定位验证码

时间:2023-02-28 14:57:34浏览次数:37  
标签:angle center point AI 验证码 点击 arc path segment

 

好的,下面是一个基于Python和selenium的示例程序,它可以根据给定的三个坐标生成随机的弧线轨迹,并模拟自然人的鼠标移动和点击操作:

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import random
import math
import time

# 设置Chrome浏览器的驱动路径
driver_path = "chromedriver.exe"

# 创建Chrome浏览器实例
driver = webdriver.Chrome(driver_path)

# 打开百度网站
driver.get("https://www.baidu.com")

# 定义加速度函数
def ease_out_quad(t):
    return t * (2 - t)

# 定义生成随机弧线轨迹的函数
def get_random_arc_path(center_x, center_y, radius, start_angle, end_angle, arc_length):
    start_angle_rad = math.radians(start_angle)
    end_angle_rad = math.radians(end_angle)
    angle_range = end_angle_rad - start_angle_rad
    arc_segments = int(arc_length / radius)
    segment_angle = angle_range / arc_segments
    path = []
    for i in range(arc_segments):
        t = i / arc_segments
        segment_start_angle = start_angle_rad + i * segment_angle
        segment_end_angle = start_angle_rad + (i + 1) * segment_angle
        segment_center_angle = (segment_start_angle + segment_end_angle) / 2
        segment_center_x = center_x + radius * math.cos(segment_center_angle)
        segment_center_y = center_y + radius * math.sin(segment_center_angle)
        segment_radius = radius / math.cos(segment_angle / 2)
        segment_arc_length = segment_radius * segment_angle
        segment_duration = 0.5 + random.random() * 0.5
        segment_path = [(segment_center_x + segment_radius * math.cos(segment_start_angle),
                         segment_center_y + segment_radius * math.sin(segment_start_angle), 0)]
        for j in range(1, 11):
            t2 = ease_out_quad(j / 10)
            segment_path.append((segment_center_x + segment_radius * math.cos(segment_start_angle + t2 * segment_angle),
                                 segment_center_y + segment_radius * math.sin(segment_start_angle + t2 * segment_angle),
                                 t + t2 * (1 - t) * segment_duration))
        path.extend(segment_path)
    return path

# 定义三个坐标
coords = [(300, 300), (500, 500), (700, 300)]

# 创建鼠标操作对象
actions = ActionChains(driver)

# 模拟鼠标移动到第一个坐标
actions.move_to_element_with_offset(driver.find_element_by_tag_name("body"), coords[0][0], coords[0][1]).perform()

# 生成随机弧线轨迹并模拟鼠标移动
arc_path = get_random_arc_path(coords[0][0], coords[0][1], 100, -90, 90, 100)
for point in arc_path:
    actions.move_to_element_with_offset(driver.find_element_by_tag_name("body"), point[0], point[1]).perform()
    time.sleep(point[2])

# 模拟鼠标点击第一个坐标
actions.click().perform()

# 生成随机弧线轨迹并模拟鼠鼠标移动到第二个坐标
arc_path = get_random_arc_path(coords[1][0], coords[1][1], 100, -90, 90, 100)
for point in arc_path:
  actions.move_to_element_with_offset(driver.find_element_by_tag_name("body"), point[0], point[1]).perform()
  time.sleep(point[2])

#模拟鼠标点击第二个坐标
actions.click().perform()

#鼠标移动到第三个坐标
arc_path = get_random_arc_path(coords[2][0], coords[2][1], 100, -90, 90, 100)
for point in arc_path:
  actions.move_to_element_with_offset(driver.find_element_by_tag_name("body"), point[0], point[1]).perform()
  time.sleep(point[2])

#模拟鼠标点击第三个坐标
actions.click().perform()

#关闭浏览器
driver.quit()

 

标签:angle,center,point,AI,验证码,点击,arc,path,segment
From: https://www.cnblogs.com/moneymaster/p/17164255.html

相关文章