嘿,伙计们,我正在尝试用selenium&;过滤一些instagram用户;python的目标是跟踪所有用户,但我不知道为什么他会返回相同的结果:
例如,此帐户:
通常情况下,他必须告诉我“有更多的追随者而不是追随者”
我的代码:
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
我的控制台日志返回:
谢谢你的帮助:)
我不确定是否粘贴了错误的缩进,但代码中的逻辑似乎有点错误
将此更改为以下内容可能会有所帮助:
而
pass
语句只是一个空语句,您可以使用continue
或break
来控制循环。但对于上面的代码,这些是循环中的最后一条语句,也带有条件语句,到目前为止,您不需要这些控制语句第二个
if
语句需要与第一个语句对齐,否则它将永远不会执行,除非满足if follower_count == 0:
条件您的代码:
结果(不正确):
正确的代码(第二个
if
语句与第一个if
语句对齐)结果:
相关问题 更多 >
编程相关推荐