Skip to content

Commit

Permalink
Refactor for JSON parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
initstring committed Oct 11, 2023
1 parent 2f20e5a commit 4ac6a44
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions linkedin2username.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,18 +494,25 @@ def find_employees(result):
print(result[:200])
return False

# When you get to the last page of results, the next page will have an empty
# "elements" list.
if result_json['data']['searchDashClustersByAll']['paging']["start"] >= result_json['data']['searchDashClustersByAll']['paging']["total"]:
# Walk the data, being careful to avoid key errors
data = result_json.get('data', {})
search_clusters = data.get('searchDashClustersByAll', {})
elements = paging = search_clusters.get('elements', [])
paging = search_clusters.get('paging', {})
total = paging.get('total', 0)

# If we've ended up with empty dicts or zero results left, bail out
if total is 0:
return False


# The "elements" list is the mini-profile you see when scrolling through a
# company's employees. It does not have all info on the person, like their
# entire job history. It only has some basics.
found_employees = []
for elements in result_json['data']['searchDashClustersByAll'].get('elements', []):
for element in elements:
# For some reason it's nested
for itemBody in elements.get('items', []):
for itemBody in element.get('items', []):
# Info we want is all under 'entityResult'
entity = itemBody['item']['entityResult']

Expand Down

0 comments on commit 4ac6a44

Please sign in to comment.