Get latest Government job information using Python


Since they provide job stability, respectable pay, and several other advantages, government jobs are in high demand worldwide. Finding and managing these notifications, though, may be a difficult process. This article will teach you how to scrape the web for the most recent government employment announcements using Python.

Installation and Syntax

Before we begin, we need to install the required Python packages. The two packages we will use are requests and BeautifulSoup. We can install these packages using pip.

Here's the command to install them:

pip install requests
pip install beautifulsoup4

Once we have installed the required packages, we can start by importing them in our Python code:

import requests
from bs4 import BeautifulSoup

Algorithm

  • First, we need to find the website where the government job notifications are listed.

  • We will then send a request to the website using the requests package in Python.

  • Next, we will extract the HTML content of the website using the content property of the response object.

  • We will then parse the HTML content using the BeautifulSoup package.

  • Finally, we will extract the relevant job notification details from the parsed HTML content.

Example

Now let's put the aforementioned algorithm to use by scraping the information from the job announcements on the Indian government's website (https://www.sarkariresult.com/latestjob).

import requests
from bs4 import BeautifulSoup

# Define the URL to scrape
url = "https://www.sarkariresult.com/latestjob.php"

# Function to get the HTML content of the website
def get_html(url):
   response = requests.get(url)
   return response.text

# Get the HTML content of the website
html_data = get_html(url)

# Parse the HTML content using BeautifulSoup
soup = BeautifulSoup(html_data, 'html.parser')

# Find the job notification details
job_details = soup.find_all("div", id="post")

# to store the scraped data
job_notifications = []

# Loop through each job notification and extract the details
for job in job_details:
   job_notification = job.get_text()
   job_notifications.append(job_notification)

# Print the job notifications
for notification in job_notifications:
   print(notification)

Output

UKPSC Jail Warden Online Form 2022 Last Date : 18/01/2023
NTA UGC NET December 2022 Online Form Last Date : 17/01/2023
Central Silk Board Various Post Online Form 2023 Last Date : 16/01/2023
MPESB High School TET Online Form 2023 Last Date : 27/01/2023
DSSSB PGT Economics Online Form 2023 Last Date : 01/02/2023
CRPF HC Ministerial and ASI Steno Online Form 2023 Last Date : 25/01/2023
AAI Junior Executives Online Form 2022  Last Date : 21/01/2023

Explanation

  • The requests module is imported to make HTTP requests to the given URL.

  • The BeautifulSoup module is imported to parse the HTML content of the webpage.

  • The URL of the website to be scraped is defined as https://www.sarkariresult.com/latestjob.php.

  • By utilizing the requests.get() method to send an HTTP request and sending the result as text, the function get html is developed to retrieve the website's HTML content.

  • By using the URL as an input when invoking the get html method, the website's HTML content may be acquired.

  • The HTML content is parsed using BeautifulSoup with the specified parser html.parser.

  • The job notification details are obtained by finding all the div tags with id="post".

  • An empty list job_notifications is initialized to store the scraped data.

  • A loop is used to extract the text from each job notification by calling the get_text() method on each div tag and appending it to the job_notifications list.

  • Finally, the job notifications are printed by looping through the job_notifications list and printing each notification.

Applications

It can be further extended to scrape job notifications from other government job portals as well. Additionally, the scraped data can be stored in a database or a CSV file for future reference or to make a job portal of the aggregated data and monetize by adding brokerage.

Conclusion

In this tutorial, we learned how to use Python to scrape government job notifications from the web. We first installed the necessary packages and then went through the algorithm in detail. We then put the algorithm into action by scraping job notification details from the Indian government's job portal. We also discussed the possible applications of the code.

Updated on: 18-Jul-2023

81 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements