Created
August 28, 2018 13:56
-
-
Save uluQulu/b453989c0b1bfdf2b75c7890aad1d9fe to your computer and use it in GitHub Desktop.
Finds user ID from page content
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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