Artur Podlesniy
Artur Podlesniy

Reputation: 155

Scrolling through instagram's follower list with python/selenium

When I click on my follower's page on instagram, a dialog box appears and I need it to scroll down and through the list. My current code works but the issue is that it scrolls too quickly and because of that instagram locks it out from viewing more profiles. What command can I use to lower scroll speed to more closely mimic a human?

WebDriverWait(driver, 10).until(lambda d: d.find_element_by_css_selector('div[role="dialog"]'))

driver.execute_script('''
    var fDialog = document.querySelector('div[role="dialog"] .isgrP');
    fDialog.scrollTop = fDialog.scrollHeight
''')

Upvotes: 0

Views: 520

Answers (1)

Raphael Rafatpanah
Raphael Rafatpanah

Reputation: 19967

You can write a function that scrolls a certain amount of pixels, then pause for a certain amount of milliseconds until a target scroll length is reached.

function scrollByPixels(px, pause, target) {
  document.documentElement.scrollTop += px
  if (target > px) {
    setTimeout(scrollByPixels, pause, px, pause, target - px)
  }
}

scrollByPixels(10, 100, 1000)
body {
  height: 1000px;
  background-image: linear-gradient(to bottom, dodgerblue, indigo);
}

Usage:

scrollByPixels(10, 100, 1000)

References:

setTimeout

Upvotes: 1

Related Questions