Skip to content

Commit

Permalink
Add search offset (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomquirk authored Aug 4, 2020
1 parent 21814c0 commit 97780d2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ A reference of country and industry codes can be found [here](https://developer.

- `params <dict>` - search parameters (see implementation of [search_people](#search_people) for a reference)
- `limit <int>` - the max number of results to return
- `offset <int>` - the offset to start the search from e.g. `offset=50` will start the search from the 50th result

**Return**

Expand Down
13 changes: 7 additions & 6 deletions linkedin_api/linkedin.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _post(self, uri, evade=default_evade, base_request=False, **kwargs):
url = f"{self.client.API_BASE_URL if not base_request else self.client.LINKEDIN_BASE_URL}{uri}"
return self.client.session.post(url, **kwargs)

def search(self, params, limit=-1):
def search(self, params, limit=-1, offset=0):
"""
Do a search.
"""
Expand All @@ -93,7 +93,7 @@ def search(self, params, limit=-1):
"filters": "List()",
"origin": "GLOBAL_SEARCH_HEADER",
"q": "all",
"start": len(results),
"start": len(results) + offset,
"queryContext": "List(spellCorrectionEnabled->true,relatedSearchesEnabled->true,kcardTypes->PROFILE|COMPANY)",
}
default_params.update(params)
Expand All @@ -105,8 +105,9 @@ def search(self, params, limit=-1):
data = res.json()

new_elements = []
for i in range(len(data["data"]["elements"])):
new_elements.extend(data["data"]["elements"][i]["elements"])
elements = data.get("data", {}).get("elements", [])
for i in range(len(elements)):
new_elements.extend(elements[i]["elements"])
# not entirely sure what extendedElements generally refers to - keyword search gives back a single job?
# new_elements.extend(data["data"]["elements"][i]["extendedElements"])
results.extend(new_elements)
Expand Down Expand Up @@ -140,13 +141,13 @@ def search_people(
schools=None,
title=None, # `keyword_title` and `title` are the same. We kept `title` for backward compatibility. Please only use one of them.
include_private_profiles=False, # profiles without a public id, "Linkedin Member"
limit=None,
# Keywords filter
keyword_first_name=None,
keyword_last_name=None,
keyword_title=None, # `keyword_title` and `title` are the same. We kept `title` for backward compatibility. Please only use one of them.
keyword_company=None,
keyword_school=None,
**kwargs,
):
"""
Do a people search.
Expand Down Expand Up @@ -188,7 +189,7 @@ def search_people(
if keywords:
params["keywords"] = keywords

data = self.search(params, limit=limit)
data = self.search(params, **kwargs)

results = []
for item in data:
Expand Down

0 comments on commit 97780d2

Please sign in to comment.