PNR Live Status using Java

PNR Live Status Java Code

When I wanted to get the PNR(Passenger Name Record) status programmatically, it can be done only using third party API’s. But none of the third party API’s are free and even if it is free then number of pnr status per day is limited. So I googled for java code to get the PNR status. I could able to see many links and programs, but as of today nothing is working.

 

Finally I took some code base from stack overflow and started writing the executable code,

http://stackoverflow.com/questions/21373498/how-to-parse-pnr-captcha-to-get-pnr-status

 

Prerequiste:

  • Apache-httpcomponents-httpcore Jar
  • jSoup Jar

 

PNR Live Status using Java:


String captcha = "24357";
String pnr1 = "4738866122";
String reqStr = "lccp_pnrno1=" + pnr1 + "&lccp_cap_value=" + captcha + "&lccp_capinp_value=" + captcha + "&submit=Please+Wait...";
StackOverflowPNR check = new StackOverflowPNR();
StringBuffer data = check.getPNRResponse(reqStr, "http://www.indianrail.gov.in/cgi_bin/inet_pnstat_cgi_1738.cgi");

// giving the html output response string to jsoup
Document doc = Jsoup.parse(data.toString());
String pnrNumber = null;

/* Retrieving the PNR Number starts */
pnrNumber = doc.select("td.Enq_heading").text();
String subStrTillNumber = pnrNumber.substring(("You Queried For : PNR Number : ".length()), pnrNumber.length());
String onlyPNRNumber = subStrTillNumber.substring(0, subStrTillNumber.indexOf("(E - TICKET)"));
String finalPNR = onlyPNRNumber.replaceAll("-", "");
//System.out.println(finalPNR);
/* Retrieving the PNR Number ends */

 

 

PNR Status Java Program Output:


TRAIN_NUMBER *16102
TRAIN_NAME CHENNAI EXPRESS
BOARDING_DATE 30- 4-2016
FROM SVGA
TO MS
RESERVED_UPTO MS
BOARDING_POINT SVGA
CLASS SL
Pass Name:::Passenger 1
Booking status:::W/L 35,GNWL
Current Status:::W/L 7
Pass Name:::Passenger 2
Booking status:::W/L 36,GNWL
Current Status:::W/L 8

 

Download the Code:

Above, I gave the sample snippet and the overview of the PNR Live Status program.

download

 

Note: I took some sample PNR number and when you are testing this program give some correct PNR number and run the program to get the PNR Live status.

 

Feel free to mention your comments/suggestions/feedbacks in the below comments section.

2,135 total views, 2 views today

About: Mirthbees

Blogger, Innovator, Developer and Enterpreneur. Founder of GuruRecharge, Readymade online recharge script. Lead Developer in Bookrate.in