Thursday 1 June 2017

PNR Status Using Python Script

Hello friends,

In this post, we'll see a Python script to fetch the PNR status of a railway ticket for a given PNR information. The script use Rail Yatri to get the PNR status. The library beautiful soup is used to extract the relevant information. The script prompts user for a PNR number and then fetches information from Rail Yatri for the PNR.

#! /usr/bin/python
import requests
from bs4 import BeautifulSoup
from time import sleep

try:
 pnr = input('Enter PNR : ')
 url = 'http://www.railyatri.in/pnr-status/' + pnr
 html = requests.get(url)
 soup = BeautifulSoup(html.text, 'lxml')
 crntStatus = soup.findAll('span', {'class':'arrival_span'})
 bkngStatus = soup.findAll('span', {'class':'departure'})
 print(bkngStatus)
 try:
  print('PNR Status', 'Booking Satus: ' + bs[1].text + '\n' + 'Curent Satus: ' + cs[2].text) 
 except:
  print("Invalid PNR. Try again!")

except requests.exceptions.ConnectionError:
 print("Connection Error. Try again!")

Share:

3 comments:

  1. Good work. Thank you for your efforts. Keep working and soon it will be very much useful to lots of students.

    ReplyDelete
  2. Hey team,
    Can any one help me to get this on my wordpress website?

    ReplyDelete

Contact Me

Name

Email *

Message *

Popular Posts