@@ -99,17 +99,34 @@ async def scroll_down(page: Page, amount: int) -> None:
9999 )
100100
101101
102+ async def simulate_human_behavior (page : Page ) -> None :
103+ """Simulate human-like mouse movements and pauses."""
104+ window_dimensions = await page .evaluate ("""
105+ () => ({
106+ width: window.innerWidth,
107+ height: window.innerHeight
108+ })
109+ """ )
110+
111+ # Move mouse to random positions within the window
112+ x = cryptogen .randint (100 , window_dimensions ["width" ] - 100 )
113+ y = cryptogen .randint (100 , window_dimensions ["height" ] - 100 )
114+ await page .mouse .move (x , y )
115+
116+ await page .wait_for_timeout (cryptogen .randint (MIN_WAIT_TIME , MAX_WAIT_TIME ))
117+
118+
102119async def perform_human_like_scroll (page : Page ) -> None :
103120 """Perform a human-like scrolling action with random variations."""
104121 scroll_amount = cryptogen .randint (MIN_SCROLL_DOWN , MAX_SCROLL_DOWN )
105122 await scroll_down (page , scroll_amount )
106- await page . wait_for_timeout ( cryptogen . randint ( MIN_WAIT_TIME , MAX_WAIT_TIME ) )
123+ await simulate_human_behavior ( page )
107124
108125 # Occasionally scroll back up
109126 if cryptogen .random () < PROBABILITY_SCROLL_UP :
110127 back_scroll = cryptogen .randint (MIN_SCROLL_UP , MAX_SCROLL_UP )
111128 await scroll_down (page , - back_scroll )
112- await page . wait_for_timeout ( cryptogen . randint ( MIN_WAIT_TIME , MAX_WAIT_TIME ) )
129+ await simulate_human_behavior ( page )
113130
114131
115132async def scroll_to_top (page : Page ) -> None :
@@ -122,7 +139,7 @@ async def scroll_to_top(page: Page) -> None:
122139 window.scrollTo(0, 0);
123140 }
124141 """ )
125- await page . wait_for_timeout ( cryptogen . randint ( MIN_WAIT_TIME , MAX_WAIT_TIME ) )
142+ await simulate_human_behavior ( page )
126143
127144
128145async def scroll_and_load_listings (page : Page , max_entries : int = 100 , max_no_change : int = 3 , max_scroll_attempts : int = 50 ) -> None :
0 commit comments