I'm using a script that gets the list of followers from my Instagram account, compares it to a .csv list of users I follow (this is the output of another script), and creates a .csv file of users I follow that don't follow me back. The .csv file looks like this (I've excluded the actual usernames):
,0 0,[username] 1,[username] 2,[username] 3,[username] I want to search each username, go to their profile, and unfollow them. This is my attempt:
def _unfollow_unfollowers(self): sleep(2) unfollowed = 0 row = 1 for x in range(1, 50): not_following_back = pd.read_csv('20210104-133708_unfollow_list.csv', delimiter=',').iloc[:,1:2] for row in not_following_back: for n in range(1, len(row)): self.browser.get("https://instagram.com/" + row[n]) sleep(2) unfollower = self.browser.find_element_by_xpath('/html/body/div[1]/section/main/div/header/section/div[1]/h2').text if unfollower in not_following_back: self.browser.find_element_by_xpath('/html/body/div[1]/section/main/div/header/section/div[1]/div[1]/div/div[2]/div/span/span[1]/button/div/span').click() if self.browser.find_element_by_xpath('/html/body/div[5]/div/div/div/div[3]/button[1]').text == 'Unfollow': self.browser.find_element_by_xpath('/html/body/div[5]/div/div/div/div[3]/button[1]').click() unfollowed += 1 row += 1 sleep(randint(30, 50)) else: print('User not found in list. Moving on to next user...') print('Unfollowed {} users.'.format(unfollowed)) return unfollowed The script doesn't search any username from the .csv file. Once it gets to this point, the process ends "successfully" and prints Unfollowed 0 users.
I'm new to Python so I'm not sure what I need to adjust.
https://stackoverflow.com/questions/65571705/use-csv-to-search-for-users-row-by-row January 05, 2021 at 08:31AM
没有评论:
发表评论