Skip to content

Instantly share code, notes, and snippets.

@uluQulu
Created August 28, 2018 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uluQulu/b453989c0b1bfdf2b75c7890aad1d9fe to your computer and use it in GitHub Desktop.
Save uluQulu/b453989c0b1bfdf2b75c7890aad1d9fe to your computer and use it in GitHub Desktop.
Finds user ID from page content
def find_user_id(browser, username, logger):
try:
user_id = browser.execute_script(
"return window._sharedData.entry_data.PostPage[0].graphql.shortcode_media.owner.id")
except WebDriverException:
try:
browser.execute_script("location.reload()")
user_id = browser.execute_script(
"return window._sharedData.entry_data.PostPage[0].graphql.shortcode_media.owner.id")
except WebDriverException:
user_id = browser.execute_script(
"return window._sharedData.entry_data.ProfilePage[0].graphql.user.id")
return user_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment