在chrome已经不受自动化工具控制情况下,web自动化验证滑块登录还是提示登录失败

时间: 2023-06-08 09:05:49 浏览: 58
这可能是由于滑块登录的验证方法不只是简单的用户名和密码,还包括了鼠标轨迹、点击位置等信息。自动化工具很难模拟这些用户行为,因此会导致登录失败的提示。建议使用其他方式进行登录验证,比如手机号码验证或者邮箱验证。
相关问题

python自动化登录滑块处理

Python自动化登录滑块处理需要用到第三方库selenium和Pillow,具体步骤如下: 1. 安装selenium和Pillow库 ``` pip install selenium pip install Pillow ``` 2. 下载Chrome浏览器驱动,将其路径添加到环境变量中 3. 编写代码,启动浏览器并打开登录页面,输入账号密码并点击登录按钮 ``` from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains from PIL import Image import time # 启动浏览器 browser = webdriver.Chrome() # 打开登录页面 browser.get('https://www.example.com/login') # 输入账号密码 username = browser.find_element_by_id('username') password = browser.find_element_by_id('password') username.send_keys('your_username') password.send_keys('your_password') # 点击登录按钮 login_button = browser.find_element_by_id('login_button') login_button.click() ``` 4. 等待页面加载完成,获取滑块图片和滑块位置 ``` # 等待页面加载完成 time.sleep(3) # 获取验证码图片和滑块位置 captcha_image = browser.find_element_by_id('captcha_image') captcha_slider = browser.find_element_by_id('captcha_slider') captcha_image_url = captcha_image.get_attribute('src') captcha_slider_location = captcha_slider.location captcha_slider_size = captcha_slider.size ``` 5. 下载验证码图片并裁剪出滑块图片 ``` # 下载验证码图片 browser.get(captcha_image_url) captcha_image_path = './captcha.png' browser.get_screenshot_as_file(captcha_image_path) # 裁剪出滑块图片 captcha_image = Image.open(captcha_image_path) left = captcha_slider_location['x'] top = captcha_slider_location['y'] right = left + captcha_slider_size['width'] bottom = top + captcha_slider_size['height'] captcha_slider_image = captcha_image.crop((left, top, right, bottom)) captcha_slider_image.save('./captcha_slider.png') ``` 6. 使用Pillow库计算滑块移动距离 ``` # 计算滑块移动距离 captcha_slider_image = Image.open('./captcha_slider.png') captcha_bg_image = Image.open('./captcha_bg.png') width, height = captcha_slider_image.size for x in range(width): for y in range(height): if is_pixel_equal(captcha_slider_image, captcha_bg_image, x, y) is False: distance = x - 6 # 滑块初始位置 break distance -= 8 # 减去滑块左侧空白部分的距离 ``` 7. 使用selenium模拟拖动滑块完成登录 ``` # 模拟拖动滑块完成登录 slider_button = browser.find_element_by_id('slider_button') ActionChains(browser).click_and_hold(slider_button).perform() ActionChains(browser).move_by_offset(distance, 0).perform() ActionChains(browser).release().perform() ``` 完整代码如下: ``` from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains from PIL import Image import time # 判断像素是否相同 def is_pixel_equal(image1, image2, x, y): pixel1 = image1.load()[x, y] pixel2 = image2.load()[x, y] threshold = 60 if abs(pixel1[0] - pixel2[0]) < threshold and abs(pixel1[1] - pixel2[1]) < threshold and abs( pixel1[2] - pixel2[2]) < threshold: return True else: return False # 启动浏览器 browser = webdriver.Chrome() # 打开登录页面 browser.get('https://www.example.com/login') # 输入账号密码 username = browser.find_element_by_id('username') password = browser.find_element_by_id('password') username.send_keys('your_username') password.send_keys('your_password') # 点击登录按钮 login_button = browser.find_element_by_id('login_button') login_button.click() # 等待页面加载完成 time.sleep(3) # 获取验证码图片和滑块位置 captcha_image = browser.find_element_by_id('captcha_image') captcha_slider = browser.find_element_by_id('captcha_slider') captcha_image_url = captcha_image.get_attribute('src') captcha_slider_location = captcha_slider.location captcha_slider_size = captcha_slider.size # 下载验证码图片 browser.get(captcha_image_url) captcha_image_path = './captcha.png' browser.get_screenshot_as_file(captcha_image_path) # 裁剪出滑块图片 captcha_image = Image.open(captcha_image_path) left = captcha_slider_location['x'] top = captcha_slider_location['y'] right = left + captcha_slider_size['width'] bottom = top + captcha_slider_size['height'] captcha_slider_image = captcha_image.crop((left, top, right, bottom)) captcha_slider_image.save('./captcha_slider.png') # 下载验证码背景图片 captcha_bg_image_url = 'https://www.example.com/captcha_bg' browser.get(captcha_bg_image_url) captcha_bg_image_path = './captcha_bg.png' browser.get_screenshot_as_file(captcha_bg_image_path) # 计算滑块移动距离 captcha_slider_image = Image.open('./captcha_slider.png') captcha_bg_image = Image.open('./captcha_bg.png') width, height = captcha_slider_image.size for x in range(width): for y in range(height): if is_pixel_equal(captcha_slider_image, captcha_bg_image, x, y) is False: distance = x - 6 # 滑块初始位置 break distance -= 8 # 减去滑块左侧空白部分的距离 # 模拟拖动滑块完成登录 slider_button = browser.find_element_by_id('slider_button') ActionChains(browser).click_and_hold(slider_button).perform() ActionChains(browser).move_by_offset(distance, 0).perform() ActionChains(browser).release().perform() ```

pycharm web自动化登录

要在PyCharm中进行Web自动化登录,你可以使用Selenium库来模拟浏览器行为。以下是一个简单的示例代码: ```python from selenium import webdriver from selenium.webdriver.common.keys import Keys # 创建一个Chrome浏览器实例 driver = webdriver.Chrome() # 打开登录页面 driver.get("https://example.com/login") # 找到用户名和密码的输入框,并输入相应的值 username_input = driver.find_element_by_name("username") password_input = driver.find_element_by_name("password") username_input.send_keys("your_username") password_input.send_keys("your_password") # 提交表单 password_input.send_keys(Keys.RETURN) # 等待登录完成,可以根据具体情况设置等待时间 driver.implicitly_wait(10) # 执行其他操作,例如访问需要登录才能访问的页面 # 关闭浏览器 driver.quit() ``` 请注意,你需要根据实际情况修改示例代码中的URL、输入框名称以及用户名和密码。另外,你还需要安装Selenium和Chrome浏览器驱动程序。你可以通过执行`pip install selenium`来安装Selenium,然后从Chrome浏览器官网下载对应版本的浏览器驱动程序并配置到系统路径中。 希望这可以帮助到你!如果有任何问题,请随时提问。

相关推荐

最新推荐

recommend-type

使用Selenium对QQ邮箱登录页面进行自动化测试

使用Selenium对QQ邮箱登录页面进行自动化测试 1.测试需求 Selenium是一个用于Web应用程序测试的工具。Selenium测试直接运行在浏览器中,就像真正的用户在操作一样。支持的浏览器包括IE(7, 8, 9, 10, 11),Mozilla ...
recommend-type

超详细的Web自动化测试环境搭建(Python+Selenium+Webdriver)

1. Web自动化测试环境如下: 脚本语言:Python 3.x 开发工具:PyCharm 自动化测试框架:Selenium 3.x 浏览器及对应驱动:Firefox(geckodriver.exe)或者Chrome(chromedriver.exe) 系统环境:windows10 2. 环境...
recommend-type

Python Selenium自动化获取页面信息的方法

1.获取页面title title:获取当前页面的标题显示的字段 from selenium import webdriver import time browser = webdriver.Chrome() ...#打印网页标题 print(browser.title) ...browser = webdriver.Chrome
recommend-type

vue中解决chrome浏览器自动播放音频和MP3语音打包到线上的实现方法

主要介绍了vue中解决chrome浏览器自动播放音频和MP3语音打包到线上的实现方法,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
recommend-type

Selenium+java进行web自动化.doc

《Selenium+java进行web自动化.doc》文档中介绍了Java的安装、Selenium IDE的安装、Selenium的使用、元素操作等。 Selenium是一个用于Web应用程序测试的工具。Selenium测试直接运行在浏览器中,就像真正的用户在操作...
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB柱状图在信号处理中的应用:可视化信号特征和频谱分析

![matlab画柱状图](https://img-blog.csdnimg.cn/3f32348f1c9c4481a6f5931993732f97.png) # 1. MATLAB柱状图概述** MATLAB柱状图是一种图形化工具,用于可视化数据中不同类别或组的分布情况。它通过绘制垂直条形来表示每个类别或组中的数据值。柱状图在信号处理中广泛用于可视化信号特征和进行频谱分析。 柱状图的优点在于其简单易懂,能够直观地展示数据分布。在信号处理中,柱状图可以帮助工程师识别信号中的模式、趋势和异常情况,从而为信号分析和处理提供有价值的见解。 # 2. 柱状图在信号处理中的应用 柱状图在信号处理
recommend-type

帮我设计一个基于Android平台的便签APP的代码

很抱歉,我是一个语言模型AI,无法提供完整的Android APP代码。但是,我可以给您一些设计便签APP的建议和思路。 1. 界面设计 首先考虑APP的界面设计,便签APP通常需要一个主界面用于显示所有的便签,以及一个编辑界面用于编辑单个便签。主界面可以采用列表的形式,列出所有的便签,每个便签可以显示标题和摘要内容。在编辑界面中,用户可以输入标题和正文内容,并且可以设置提醒时间、标签、优先级等。 2. 数据存储 便签APP需要一个数据存储的方案,可以考虑使用SQLite数据库来存储便签数据。每个便签可以存储标题、正文内容、提醒时间、标签、优先级等信息。 3. 便签操作 便签APP
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。