I am using selenium and trying to scroll inside the popup div on instagram.
I get to a page like 'https://www.instagram.com/kimkardashian/', click followers, and then I can't get the followers list to scroll down.
I tried using hover, click_and_hold, and a few other tricks to select the div but none of them worked.
What would the best way be to get this selected?
This is what I tried so far:
driver.find_elements_by_xpath("//*[contains(text(), 'followers')]")[0].click()
element_to_hover_over = driver.find_elements_by_xpath("//*[contains(text(), 'Follow')]")[12]
hover = ActionChains(webdriver).move_to_element(element_to_hover_over)
hover.click_and_hold()
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
The exact code is as follow. You first have to find the new iframe which contains the name of followers:
scr1 = driver.find_element_by_xpath('/html/body/div[2]/div/div[2]/div/div[2]')
driver.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", scr1)
This will automatically scroll down the page but you have make a for loop for it until it reaches to the end of page. You can see my Instagram crawler here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With