MCPcopy
hub / github.com/InstaPy/InstaPy / get_username

Function get_username

instapy/util.py:1677–1711  ·  view source on GitHub ↗

Get the username of a user from the loaded profile page

(browser, track, logger)

Source from the content-addressed store, hash-verified

1675
1676
1677def get_username(browser, track, logger):
1678 """Get the username of a user from the loaded profile page"""
1679
1680 query = None
1681
1682 if track == "profile":
1683 query = "return window._sharedData.entry_data. \
1684 ProfilePage[0].graphql.user.username"
1685
1686 elif track == "post":
1687 query = "return window._sharedData.entry_data. \
1688 PostPage[0].graphql.shortcode_media.owner.username"
1689
1690 try:
1691 username = browser.execute_script(query)
1692
1693 except WebDriverException:
1694 try:
1695 browser.execute_script("location.reload()")
1696 update_activity(browser, state=None)
1697
1698 username = browser.execute_script(query)
1699
1700 except WebDriverException:
1701 current_url = get_current_url(browser)
1702 logger.info(
1703 "Failed to get the username from '{}' page".format(
1704 current_url or "user" if track == "profile" else "post"
1705 )
1706 )
1707 username = None
1708
1709 # in future add XPATH ways of getting username
1710
1711 return username
1712
1713
1714def find_user_id(browser, track, username, logger):

Callers 1

get_username_from_idFunction · 0.85

Calls 3

update_activityFunction · 0.85
get_current_urlFunction · 0.85
execute_scriptMethod · 0.80

Tested by

no test coverage detected