def likers_from_post(browser, logger, Selectors, amount=20): """ Get the list of users from the 'Likes' dialog of a photo """ liked_counter_button = '//form/div/div/div/div/div/span/span/a[@role="button"]' try: liked_this = browser.find_elements_by_xpath(liked_counter_button) element_to_click = liked_this[0] sleep(1) click_element(browser, Settings, element_to_click) logger.info("opening likes") # update server calls # update_activity(Settings) sleep(1) # get a reference to the 'Likes' dialog box dialog = browser.find_element_by_xpath( Selectors.likes_dialog_body_xpath) # scroll down the page previous_len = -1 browser.execute_script( "arguments[0].scrollTop = arguments[0].scrollHeight", dialog) update_activity(Settings) sleep(1) start_time = time.time() user_list = [] while (not user_list or (len(user_list) != previous_len) and (len(user_list) < amount)): previous_len = len(user_list) scroll_bottom(browser, dialog, 2) user_list = get_users_from_dialog(user_list, dialog, logger) # write & update records at Progress Tracker progress_tracker(len(user_list), amount, start_time, None) if previous_len + 10 >= amount: logger.info("Scrolling finished") sleep(1) break random.shuffle(user_list) sleep(1) close_dialog_box(browser) logger.info("Got {} likers shuffled randomly whom you can follow:\n{}" "\n".format(len(user_list), user_list)) return user_list except Exception as exc: logger.Error("Some problem occured!\n\t{}".format( str(exc).encode("utf-8"))) return []
def likers_from_post(browser, logger, Selectors, amount=20): """ Get the list of users from the 'Likes' dialog of a photo """ liked_counter_button = \ '//form/div/div/div/div/div/span/span/a[@role="button"]' try: liked_this = browser.find_elements_by_xpath(liked_counter_button) element_to_click = liked_this[0] # print('element_to_click:', element_to_click) # likers = [] # for liker in liked_this: # if " like this" not in liker.text: # likers.append(liker.text) # if check_exists_by_xpath(browser, liked_counter_button): # if " others" in liked_this[-1].text: # element_to_click = liked_this[-1] # elif " likes" in liked_this[0].text: # element_to_click = liked_this[0] # else: # print("Few likes, not guaranteed you don't follow these" # " likers already.\nGot photo likers: {}\n" # .format(likers)) # return likers # else: # print("Couldn't find liked counter button. May be a video.") # print("Moving on..") # return [] sleep(1) click_element(browser, Settings, element_to_click) print("opening likes") # update server calls # update_activity(Settings) sleep(1) # get a reference to the 'Likes' dialog box dialog = browser.find_element_by_xpath( Selectors.likes_dialog_body_xpath) # scroll down the page previous_len = -1 browser.execute_script( "arguments[0].scrollTop = arguments[0].scrollHeight", dialog) update_activity(Settings) sleep(1) start_time = time.time() user_list = [] while (not user_list or (len(user_list) != previous_len) and (len(user_list) < amount)): previous_len = len(user_list) scroll_bottom(browser, dialog, 2) user_list = get_users_from_dialog(user_list, dialog, logger) # print('user_list (loop):') # print(user_list) # write & update records at Progress Tracker progress_tracker(len(user_list), amount, start_time, None) if previous_len + 10 >= amount: print("\nScrolling finished") sleep(1) break print('\n') # print('user_list:') # print(user_list) random.shuffle(user_list) sleep(1) close_dialog_box(browser) print("Got {} likers shuffled randomly whom you can follow:\n{}" "\n".format(len(user_list), user_list)) return user_list except Exception as exc: print("Some problem occured!\n\t{}".format(str(exc).encode("utf-8"))) return []