DEV Community

Cover image for Job Search API
Anuoluwapo Balogun
Anuoluwapo Balogun

Posted on

Job Search API

The purpose of this project is to get data using api.

This is my first project using api to get data

I did this project with guidance from 365 Data Science

Link to the API Documentation I used Job Search API

Importing Necessary Libraries

import requests
import json

url = "https://jsearch.p.rapidapi.com/search"

querystring = {"query":"Data Analyst in Lagos, Nigeria","num_pages":"1"}

headers = {
    "X-RapidAPI-Key": "374e7caff4mshbdf0dc9feaf2c44p1807dfjsn55b29ff65a00",
    "X-RapidAPI-Host": "jsearch.p.rapidapi.com"
}

response = requests.request("GET", url, headers=headers, params=querystring)

respond = response.json()
Enter fullscreen mode Exit fullscreen mode
# View the API result

print(json.dumps(respond, indent = 4))
Enter fullscreen mode Exit fullscreen mode
# View the api keys

respond.keys()

Output
dict_keys(['status', 'request_id', 'data'])
Enter fullscreen mode Exit fullscreen mode
# View the data key result

print(json.dumps(respond['data'][0], indent=4))
Enter fullscreen mode Exit fullscreen mode
# View the request_id key

respond["request_id"]

Output
'3702f9d9-3f27-4d12-9224-6040141d9d83'
Enter fullscreen mode Exit fullscreen mode

Turning data into tabular form with pandas with the api collection key (data)

import pandas
df = pd.DataFrame(respond['data'])
df
Enter fullscreen mode Exit fullscreen mode
# Optional
# Remove the unecessary columns

data = df.drop(columns = ["job_description", "employer_logo","employer_website", "job_id",
                         "job_posted_at_timestamp", "job_posted_at_datetime_utc", "job_latitude",
                         "job_longitude", "job_google_link","job_offer_expiration_datetime_utc","job_experience_in_place_of_education",
                          "job_min_salary", "job_max_salary","job_salary_currency",
                          "job_salary_period", "job_highlights", "job_benefits"], inplace = True)
Enter fullscreen mode Exit fullscreen mode

Transforming and saving data into a csv file format

df.to_csv (r'data.csv', encoding = 'utf-8', index = None)

job = pd.read_csv('data.csv')

job.head()
Enter fullscreen mode Exit fullscreen mode
# Check the data info

job.info()
Enter fullscreen mode Exit fullscreen mode

You should see your saved csv format in the file path you saved it into

Top comments (0)