do you have any idea why it unfollow only 15 people instead of all?
You need an account at Instagram to run this script.
for example:
if your account is chrome1
than this script will be working on
https://www.instagram.com/chrome1/following/
for ns in driver.find_elements_by_class_name("_6jvgy"):
try:
ns.find_element_by_class_name("_r4e4p").click() # unFollow button!!!
# time.sleep(2) # the same as without sleep
unfollow_nick = ns.find_element_by_class_name("notranslate").get_attribute("title")
print(unfollow_nick) # now: prints all, but really unfollow only 15.
except:
pass
this question is a continuation of the previous: Scroll in Selenium Webdriver (Python)
all the code needed to run: https://ideone.com/wYjHW4
It is the speed of requests (clicking continuously on
Following
button) that causing Instagram server to reject/ignore the majority of requests.Add some sleep time before each request.
In your code, you imported
sleep
method. so, directly usesleep(2)
but nottime.sleep
, which throws the exception and you are capturing it & bypassed it usingpass
keyword, so you are not aware of this exception. I suggest print the exception and then usepass
keyword.