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 moduleimport requestsimport pandas as pdfrom bs4 import BeautifulSoupres = ''# link for extract html datadef getdata(url): r = requests.get(url) return r.textsoup = 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 moduleimport requestsimport pandas as pdfrom bs4 import BeautifulSoupfrom tkinter import *from tkinter import messageboxres = []def getdata(url): r = requests.get(url) return r.textdef getinfo(): result = '' 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 greymaster = Tk()master.configure(bg='light grey')# Variable Classes in tkinterres = StringVar()# Creating label for each information# name using widget LabelLabel(master, text="List of the Jobs :", bg="light grey", font="100").grid(row=0, sticky=W)# Creating label for class variable# name using widget EntryLabel(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 functionb = Button(master, text="Get latest job", command=getinfo)b.grid(row=0, column=2, columnspan=2, rowspan=2, padx=5, pady=5)mainloop() |
Output:

