|
|
|
|
@ -83,12 +83,49 @@ def extract_script_tags(username):
|
|
|
|
|
except requests.exceptions.RequestException as e:
|
|
|
|
|
return f"Error fetching the URL: {e}"
|
|
|
|
|
|
|
|
|
|
def find_item_in_json(json_data, key):
|
|
|
|
|
"""
|
|
|
|
|
Recursively searches for the first occurrence of a key in a JSON-like structure (dict or list).
|
|
|
|
|
|
|
|
|
|
:param json_data: JSON data (dict or list) to search.
|
|
|
|
|
:param key: The key to find.
|
|
|
|
|
:return: The value of the first occurrence of the key, or None if not found.
|
|
|
|
|
"""
|
|
|
|
|
if isinstance(json_data, dict):
|
|
|
|
|
for k, v in json_data.items():
|
|
|
|
|
if k == key:
|
|
|
|
|
return v
|
|
|
|
|
elif isinstance(v, (dict, list)):
|
|
|
|
|
result = find_item_in_json(v, key)
|
|
|
|
|
if result is not None:
|
|
|
|
|
return result
|
|
|
|
|
elif isinstance(json_data, list):
|
|
|
|
|
for item in json_data:
|
|
|
|
|
if isinstance(item, (dict, list)):
|
|
|
|
|
result = find_item_in_json(item, key)
|
|
|
|
|
if result is not None:
|
|
|
|
|
return result
|
|
|
|
|
return None # Return None if the key is not found
|
|
|
|
|
|
|
|
|
|
def get_user_id(username):
|
|
|
|
|
scripts = extract_script_tags(username)
|
|
|
|
|
"""
|
|
|
|
|
Extracts the user ID (profile_id) from JSON data embedded in script tags for a given username.
|
|
|
|
|
|
|
|
|
|
:param username: The username to process.
|
|
|
|
|
:return: The user ID (profile_id) if found, otherwise None.
|
|
|
|
|
"""
|
|
|
|
|
scripts = extract_script_tags(username) # Replace this with your implementation
|
|
|
|
|
for script in scripts:
|
|
|
|
|
if "profile_id" in str(script):
|
|
|
|
|
json_data = json.loads(script.string)
|
|
|
|
|
return user_id
|
|
|
|
|
try:
|
|
|
|
|
json_data = json.loads(script.string) # Parse JSON from the script
|
|
|
|
|
user_id = find_item_in_json(json_data, 'profile_id') # Search for 'profile_id'
|
|
|
|
|
if user_id:
|
|
|
|
|
return user_id
|
|
|
|
|
except (json.JSONDecodeError, AttributeError):
|
|
|
|
|
# Handle JSON decoding errors or missing script content
|
|
|
|
|
continue
|
|
|
|
|
return None # Return None if no 'profile_id' is found
|
|
|
|
|
|
|
|
|
|
def get_profile_data(username):
|
|
|
|
|
url = 'https://www.instagram.com/graphql/query'
|
|
|
|
|
@ -133,11 +170,10 @@ def get_profile_data(username):
|
|
|
|
|
return json_data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
user_id = get_user_id('intergalacticum')
|
|
|
|
|
|
|
|
|
|
username_check = 'tal_ohana'
|
|
|
|
|
|
|
|
|
|
user_id = get_user_id(username_check)
|
|
|
|
|
|
|
|
|
|
user_id = 10217929812
|
|
|
|
|
username = get_username_by_user_id(user_id)
|
|
|
|
|
|
|
|
|
|
if username:
|
|
|
|
|
|