Home > Software design >  How can i get the length of entire list of followers instagram with selenium
How can i get the length of entire list of followers instagram with selenium

Time:04-21

Hellow! I want to iterate over entire list of followers on instagram but it gets me just the first 13 elements! Why this happend? enter image description here

abc = driver.find_elements_by_xpath('//div[@]')
for i in abc:
     if i.text == 'Follow':
        driver.execute_script("arguments[0].click();", i)
enter image description here

Any ideea how to click on all ements from the followrs pop up?

CodePudding user response:

I'm going to assume that you're looking at a list of followers on Instagram.

So here is a random page on IG: IG screencap

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

More elements load in when scrolling down: IG screencap You can see enter image description here (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

CodePudding user response:

It looks like it finds something but the process stops right after that

it says just this:

FollowButtons = driver.find_elements_by_css_selector('div[aria-label="Followers"] >div >div >div:nth-child(2) > ul li button')

And the size of list is = 0 FollowButtons is size 0

CodePudding user response:

If i use that code, the size of the followBttons variable is 0. That means the list is empty! Any idea why?

  • Related