Python运算符过滤器无效(Selenium) [英] Python operator filter dosen't work (Selenium)
问题描述
大家好,我想用硒&过滤掉一些instagram用户.python,目标是使所有用户关注的人数都多于关注者,但我不知道他为什么会返回相同的结果:
Hey guys I am trying to filtered a few instagram users with selenium & python, the goal is to following all user have more following than followers but i don't know why he return me same result:
此帐户的示例:
通常,他必须打印出我跟随者多于关注者"
Normaly it he must to print me "have more followers than following"
我的代码:
followers = [] #list of url users
for follower in followers:
#Iterate into the list
scrap_follower = browser.find_element_by_xpath('/html/body/div[1]/section/main/div/header/section/ul/li[2]/a/span').get_attribute("title")
scrap_following = browser.find_element_by_xpath('/html/body/div[1]/section/main/div/header/section/ul/li[3]/a/span').text
follower_count = int(scrap_follower)
following_count = int(scrap_following)
browser.get(follower)
sleep(2)
followButton = browser.find_element_by_css_selector('button')
print(follower_count)
print(following_count)
if follower_count == 0:
pass
print("0 followers")
if follower_count > following_count :
print("have more followers than following")
pass
else:
print("eligible")
#Go to follow
我的控制台日志返回:
感谢您的帮助:)
推荐答案
第二条 if
语句需要与第一个语句对齐,否则除非 if follower_count == 0,否则它将永远不会执行:
条件得到满足.
Your second if
statement needs to align with the first one otherwise it will never execute unless the if follower_count == 0:
condition is met.
您的代码:
follower_count = 1500
following_count = 1000
print(follower_count)
print(following_count)
if follower_count == 0:
pass
print("0 followers")
if follower_count > following_count :
print("have more followers than following")
pass
else:
print("eligible")
结果(不正确):
1500
1000
eligible
正确的代码(第二条 if
语句与第一条 if
语句对齐)
Correct code (2nd if
statement aligned with first if
statement)
follower_count = 1500
following_count = 1000
print(follower_count)
print(following_count)
if follower_count == 0:
pass
print("0 followers")
if follower_count > following_count :
print("have more followers than following")
pass
else:
print("eligible")
结果:
1500
1000
have more followers than following
这篇关于Python运算符过滤器无效(Selenium)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!