Skip to content
Related Articles

Related Articles

Improve Article

Get latest Government job information using Python

  • Last Updated : 29 Dec, 2020

Prerequisite: Python GUI – tkinter 

In these articles, we are going to write python scripts to get the latest Government job information.

Modules Needed

  • BeautifulSoup: Beautiful Soup(bs4) is a Python library for pulling data out of HTML and XML files. This module does not come built-in with Python. To install this type the below command in the terminal.
pip install bs4
  • requests: Requests allows you to send HTTP/1.1 requests extremely easily. This module also does not comes built-in with Python. To install this type the below command in the terminal.
pip install requests

Approach:

  • Extract data form given URL
  • Scrape the data with the help of requests and Beautiful Soup
  • Convert that data into HTML code.
  • Find the required details and filter them.

Let’s see the stepwise execution of the script

Step 1: Import all dependence  



Python3




import requests 
from bs4 import BeautifulSoup

Step 2: Create a URL get function

Python3




def getdata(url): 
    r = requests.get(url) 
    return r.text

Step 3: Now pass the URL into the getdata function and Convert that data into HTML code

Python3




# import module
import requests
import pandas as pd
from bs4 import BeautifulSoup
  
  
res = ''
  
# link for extract html data
def getdata(url):
    r = requests.get(url)
    return r.text
  
soup = BeautifulSoup(htmldata, 'html.parser')
  
for li in soup.find_all("div", id="post"):
    res += (li.get_text())
  
print(res)

Output:

Application for the Latest job information with Tkinter: This Script implements the above Implementation into a GUI.

Python3




# import module
import requests
import pandas as pd
from bs4 import BeautifulSoup
from tkinter import *
from tkinter import messagebox
  
res = []
  
  
def getdata(url):
    r = requests.get(url)
    return r.text
  
  
def getinfo():
    result = ''
    htmldata = getdata("https://www.sarkariresult.com/latestjob.php")
    soup = BeautifulSoup(htmldata, 'html.parser')
      
    for li in soup.find_all("div", id="post"):
        result += (li.get_text())
    res.set(result)
  
  
# object of tkinter
# and background set for light grey
master = Tk()
master.configure(bg='light grey')
  
# Variable Classes in tkinter
res = StringVar()
  
# Creating label for each information
# name using widget Label
Label(master, text="List of the Jobs :",
      bg="light grey", font="100").grid(row=0, sticky=W)
  
# Creating lebel for class variable
# name using widget Entry
Label(master, text="", textvariable=res, bg="light grey").grid(
    row=3, column=1, sticky=W)
  
# creating a button using the widget
# Button that will call the submit function
b = Button(master, text="Get latest job", command=getinfo)
b.grid(row=0, column=2, columnspan=2, rowspan=2, padx=5, pady=5)
  
mainloop()

Output:

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :