你知道为什么只有15个人参加吗 而不是全部?在
你需要一个Instagram帐户来运行这个脚本。在
例如:
如果您的帐户是chrome1
此脚本将用于
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
这个问题是前一个问题的延续: Scroll in Selenium Webdriver (Python)
运行所需的所有代码: https://ideone.com/wYjHW4
正是请求的速度(连续单击
Following
按钮)导致Instagram服务器拒绝/忽略大多数请求。在每个请求之前增加一些睡眠时间。
在代码中,导入了
sleep
方法。因此,直接使用sleep(2)
而不是time.sleep
,这会抛出异常并捕获它,并使用pass
关键字绕过它,因此您不知道该异常。我建议打印异常,然后使用pass
关键字。相关问题 更多 >
编程相关推荐