I think you are looking for something like this, you can use len()
instead of looping through and counting the "id" attribute.
import requests
baseurl = "https://jobs.github.com/positions.json"
def get_number_of_jobs(technology):
job_count = 50
total_job_count = 0
page_count = 1
while job_count > 49:
job_count = 0
# send request to GitHub for the next page
tech = {'description': technology, 'page': page_count}
response = requests.get(baseurl, params=tech)
if response.ok:
jobs = response.json()
page_count += 1
job_count = len(jobs)
total_job_count += job_count
return technology,total_job_count
print(get_number_of_jobs("java"))
The first call you make is page 1, so you would be calling page 1 twice in your algorithm, you can start at 1 and if > 49 continue to loop through.
Python result:
Github job posting for Java:
Let me know if you need anything clarifying,
Thanks,
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…