我有一个学校项目,我的程序必须执行此代码才能关注两个用户:
def followWithUsername(self):
usernames = ['therock', 'justinbieber']
self.driver.get('https://instagram.com/' + str(usernames) + '/')
time.sleep(3)
followButton = self.driver.find_element_by_css_selector('button')
if (followButton.text != 'Following'):
followButton.click()
time.sleep(3)
else:
print("You are already following this user.")
我尝试了各种方法,但这不会将用户名彼此分开并一一执行
最佳答案
使用for
循环:
def followWithUsername(self):
usernames = ['therock', 'justinbieber']
for name in usernames:
self.driver.get('https://instagram.com/' + name + '/')
time.sleep(3)
followButton = self.driver.find_element_by_css_selector('button')
if (followButton.text != 'Following'):
followButton.click()
time.sleep(3)
else:
print("You are already following this user.")
关于python - 我在将列表作为自动化函数的字符串执行时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59350206/