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[@]')
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?
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:
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 (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?