'How can i get the length of entire list of followers instagram with selenium
Hellow! I want to iterate over entire list of followers on instagram but it gets me just the first 13 elements! Why this happend?
abc = driver.find_elements_by_xpath('//div[@class="_7UhW9 xLCgt qyrsm uL8Hv T0kll "]')
for i in abc:
if i.text == 'Follow':
driver.execute_script("arguments[0].click();", i)
Any ideea how to click on all ements from the followrs pop up?
Solution 1:[1]
I'm going to assume that you're looking at a list of followers on Instagram.
So here is a random page on IG:

They have 218,000 followers but when I click to see, I only see 24 followers:

More elements load in when scrolling down:
You can see this answer for how to scroll within a specific element
If you would want to get all the followers, I would recommend looping your scrollToBottom() method until the last element stops changing. I don't know how well this will work for 218,000 elements though.
To select the scrolling area, you'll need to find a CSS selector or XPath that matches with this element. Since all the classes here look like they are autogenerated they keep changing, so I found that this selector gets the scrolling area everytime: div[aria-label="Followers"] >div >div >div:nth-child(2)
(I try to just use CSS selectors when working with Selenium, but you can use XPath if you want)
In Selenium, to access the element you can use
element = driver.find_element_by_css_selector('div[aria-label="Followers"] >div >div >div:nth-child(2)')
After loading in however many elements you want, you just gotta use the find_elements_by_css_selector() method to get the followers.
I've found this one works consistently:
div[aria-label="Followers"] >div >div >div:nth-child(2) > ul li
If you're just trying to mass follow all these people, I would advise against it, you might get flagged if you don't add some delay between clicks. But simply you could do this:
followButtons = driver.find_elements_by_css_selector('div[aria-label="Followers"] >div >div >div:nth-child(2) > ul li button')
for butt in followButtons:
butt.click()
If anything happens though, I wasn't involved
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Diego Cuadros |
