bounty将在21小时后过期。回答此问题可获得+100声望奖励。Mévatlavé Kraspek希望引起更多关注此问题。
我尝试这个代码:Human-like mouse movements via Selenium但是试图弄清楚如何将其集成到真实的生活中的scraper来跟随我的鼠标圆顶DOM元素:
#!/usr/bin/python
# https://stackoverflow.com/questions/39422453/human-like-mouse-movements-via-selenium
import os
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
import numpy as np
import scipy.interpolate as si
#curve base
points = [[-6, 2], [-3, -2],[0, 0], [0, 2], [2, 3], [4, 0], [6, 3], [8, 5], [8, 8], [6, 8], [5, 9], [7, 2]];
points = np.array(points)
x = points[:,0]
y = points[:,1]
t = range(len(points))
ipl_t = np.linspace(0.0, len(points) - 1, 100)
x_tup = si.splrep(t, x, k=3)
y_tup = si.splrep(t, y, k=3)
x_list = list(x_tup)
xl = x.tolist()
x_list[1] = xl + [0.0, 0.0, 0.0, 0.0]
y_list = list(y_tup)
yl = y.tolist()
y_list[1] = yl + [0.0, 0.0, 0.0, 0.0]
x_i = si.splev(ipl_t, x_list)
y_i = si.splev(ipl_t, y_list)
url = "https://codepen.io/falldowngoboone/pen/PwzPYv"
driver = webdriver.Chrome()
driver.get(url)
action = ActionChains(driver);
startElement = driver.find_element(By.ID, 'drawer')
# First, go to your start point or Element:
action.move_to_element(startElement);
action.perform();
# https://stackoverflow.com/a/70796266/465183
for mouse_x, mouse_y in zip(x_i, y_i):
# Here you should reset the ActionChain and the 'jump' wont happen:
action = ActionChains(driver)
action.move_by_offset(mouse_x,mouse_y);
action.perform();
print(mouse_x, mouse_y)
是否有类似NodeJS/pptr Ghost Cursor的Python模块来方便集成?
或者这里的任何人都可以向我们展示一种将其集成到真实的生活中的刮刀中的方法?
1条答案
按热度按时间slsn1g291#
**一个
https://youtu.be/zZfPST2QS-g
我认为有一个更好的方法,像我在这里做的那样使用Bezier curves,像你的github链接建议的那样使用
Selenium ActionsChains
,重写类来做像driver.move_to_element()
和driver.random_mouse()
这样的事情,但这对于简单的需求来说效果很好:代码以避免仅链接回答:
paw文件:
其余的文物在仓库。
运行 Package 脚本: