首页 > 解决方案 > 使用 .click() 或 .move_to_element() Selenium Python 模拟鼠标移动

问题描述

我正在做一个 Selenium 机器人项目,我注意到网站可以很容易地检测到机器人正在通过网站购买获取光标的 X 和 Y,因为 driver.click() 函数直接跳转到元素。有什么方法可以模拟鼠标移动以防止检测。

findtop = driver.find_element_by_class_name('topbutton').click()
time.sleep(3)
findbottom = driver.find_element_by_class_name('bottomButton').click()

这是我在控制台中得到的:

X:26 Y: 19
X:1006 Y: 707

我什至尝试过:

findtop = driver.find_element_by_class_name('topbutton').click()
time.sleep(3)
findbottom = driver.find_element_by_class_name('bottomButton')

webdriver.ActionChains(driver).move_to_element(findtop).perform()

findbottom = driver.find_element_by_class_name('bottomButton')
webdriver.ActionChains(driver).move_to_element(findbottom).perform()

结果相同。

标签: pythonseleniumselenium-webdriverselenium-chromedriverbots

解决方案


推荐阅读