MCPcopy
hub / github.com/InstaPy/InstaPy / get_relationship_counts

Function get_relationship_counts

instapy/util.py:1175–1288  ·  view source on GitHub ↗

Gets the followers & following counts of a given user

(browser, username, logger)

Source from the content-addressed store, hash-verified

1173
1174
1175def get_relationship_counts(browser, username, logger):
1176 """Gets the followers & following counts of a given user"""
1177
1178 user_link = "https://www.instagram.com/{}/".format(username)
1179
1180 # check URL of the webpage, if it already is user's profile page,
1181 # then do not navigate to it again
1182 web_address_navigator(browser, user_link)
1183
1184 try:
1185 followers_count = browser.execute_script(
1186 "return window._sharedData.entry_data."
1187 "ProfilePage[0].graphql.user.edge_followed_by.count"
1188 )
1189
1190 except WebDriverException:
1191 try:
1192 followers_count = format_number(
1193 browser.find_element(
1194 By.XPATH,
1195 str(
1196 read_xpath(get_relationship_counts.__name__, "followers_count")
1197 ),
1198 ).text
1199 )
1200 except NoSuchElementException:
1201 try:
1202 browser.execute_script("location.reload()")
1203 update_activity(browser, state=None)
1204
1205 followers_count = browser.execute_script(
1206 "return window._sharedData.entry_data."
1207 "ProfilePage[0].graphql.user.edge_followed_by.count"
1208 )
1209
1210 except WebDriverException:
1211 try:
1212 topCount_elements = browser.find_elements(
1213 By.XPATH,
1214 read_xpath(
1215 get_relationship_counts.__name__, "topCount_elements"
1216 ),
1217 )
1218
1219 if topCount_elements:
1220 followers_count = format_number(topCount_elements[1].text)
1221 else:
1222 logger.info(
1223 "Failed to get followers count of '{}' ~empty "
1224 "list".format(username.encode("utf-8"))
1225 )
1226 followers_count = None
1227
1228 except NoSuchElementException:
1229 logger.error(
1230 "Error occurred during getting the followers count "
1231 "of '{}'\n".format(username.encode("utf-8"))
1232 )

Callers 6

unfollowFunction · 0.85
get_given_user_followersFunction · 0.85
validate_usernameFunction · 0.85
save_account_progressFunction · 0.85
get_followersFunction · 0.85
get_followingFunction · 0.85

Calls 7

web_address_navigatorFunction · 0.85
format_numberFunction · 0.85
read_xpathFunction · 0.85
update_activityFunction · 0.85
EventClass · 0.85
execute_scriptMethod · 0.80
profile_data_updatedMethod · 0.80

Tested by

no test coverage detected