cleanup and fix runtime bugs
This commit is contained in:
@@ -10,11 +10,9 @@ class HumanPacer:
|
||||
"""Random паузы между действиями."""
|
||||
|
||||
def __init__(self, settings: Settings) -> None:
|
||||
# Инкапсулирует все задержки между действиями браузера.
|
||||
self.settings = settings
|
||||
|
||||
def pause(self, min_s: float, max_s: float) -> None:
|
||||
# Базовая случайная пауза в заданном диапазоне.
|
||||
if self.settings.pace.enabled:
|
||||
time.sleep(random.uniform(min_s, max_s))
|
||||
|
||||
@@ -37,13 +35,12 @@ class HumanPacer:
|
||||
self.pause(self.settings.pace.after_page_change_min_s, self.settings.pace.after_page_change_max_s)
|
||||
|
||||
def move_mouse_to(self, page: Page, locator: Locator) -> None:
|
||||
# Небольшое движение мыши к элементу перед кликом.
|
||||
try:
|
||||
box = locator.bounding_box()
|
||||
except Exception:
|
||||
box = None
|
||||
if not box:
|
||||
return
|
||||
x = box["x"] + min(box["width"] * 0.6, max(5, box["width"] * random.uniform(0.2, 0.8)))
|
||||
y = box["y"] + min(box["height"] * 0.6, max(5, box["height"] * random.uniform(0.2, 0.8)))
|
||||
x = box["x"] + box["width"] * random.uniform(0.2, 0.8)
|
||||
y = box["y"] + box["height"] * random.uniform(0.2, 0.8)
|
||||
page.mouse.move(x, y, steps=random.randint(8, 18))
|
||||
|
||||
Reference in New Issue
Block a user