【发布时间】:2020-12-03 10:56:09
【问题描述】:
这是一个 python 代码并列出我只关注他们的用户。我想通过添加一个自动取消关注的模块来使用相同的列表:
。 . .
def get_unfollowers(browser):
"""
Opens the profile, obtains the follower and following list
Returns the names of the users who are in the following list, but not in the follower list
"""
to_profile = browser.find_element_by_xpath("//a[contains(@href, '/{}')]".format(username))
to_profile.click()
sleep(3)
to_following = browser.find_element_by_xpath("//a[contains(@href, '/following')]")
to_following.click()
following_list = get_name(browser)
to_followers = browser.find_element_by_xpath("//a[contains(@href, '/followers')]")
to_followers.click()
followers_list = get_name(browser)
not_following_back = [user for user in following_list if user not in followers_list]
print(not_following_back) # prints a list with every name separated by a comma
def get_name(browser):
sleep(2)
scroll_box = browser.find_element_by_class_name('isgrP')
p_height, height = 0, 1
while p_height != height:
p_height = height
sleep(2)
height = browser.execute_script(
"arguments[0].scrollTo(0, arguments[0].scrollHeight); return arguments[0].scrollHeight;", scroll_box)
total_list = scroll_box.find_elements_by_tag_name('li')
names = [name.text for name in total_list if name.text != '']
close_dub = browser.find_element_by_xpath("/html/body/div[4]/div/div/div[1]/div/div[2]/button")
close_dub.click()
return names
get_unfollowers(browser)
【问题讨论】:
标签: python python-3.x pycharm instagram