0

I'm looking for a way to get best flying ticket price from website just by parsing it in Java, at start from this particular site :

http://www.kayak.com/flights

for example I'm looking for a flight Gdańsk > Barcelona with some random data:

http://www.kayak.com/flights/GDN-BCN/2015-04-20/2015-04-27

things I've done:

  • Found div's I'd like to get from parsing at browser in programmers mode:

div class="sliderFilterLabel">
span id="low_price"> class="min">73 €

on this spot there should be always lowest price.

  • tried to parse it using Jsoup and I've found out that code misses most valuable for me divs.

How could I find it or is there any more efficient way to get just one number from whole website.

My code:

Document doc;
try {
// need http protocol
doc = Jsoup.connect("https://www.kayak.pl/flights/GDN,nearby-IBZ,nearby/2015-04-20/2015-04-27").userAgent("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36").get();
System.out.println(doc);

there is almost no code. After a few tries with jsoup I printed out whole website that I parse and I cannot find divs I need.

Pshemo
  • 122,468
  • 25
  • 185
  • 269
BaKu
  • 17
  • 7
  • 3
    As with most similar questions, why not first show the code you've created and describe how it's not working for you? Else, how will we know what you're doing wrong. And by showing your code you change a somewhat "please code this for me" type question into a much better "please help me understand how to fix my code and misconceptions" type question. – Hovercraft Full Of Eels Apr 14 '15 at 15:59
  • Sorry mate, I'm tottaly not here to 'write code for me' more like where to find the answer or how to find code hidden via that site. – BaKu Apr 14 '15 at 16:32
  • 3
    That website loads its data with JavaScript, which Jsoup cannot do. Try [their api instead](http://www.programmableweb.com/api/kayak), or [some other travel api](http://www.programmableweb.com/news/134-travel-apis-kayak-yahoo-travel-and-hotelscombined/2012/02/28). Also read [this](http://stackoverflow.com/questions/4607141/how-does-a-site-like-kayak-com-aggregate-content). – Jonas Czech Apr 14 '15 at 16:34
  • I'm trying to do it with PhanthomJS, so hopefully edit soon. – BaKu Apr 14 '15 at 21:46
  • Try this with Selenium+PhantomJSDriver/Ghostdriver, you will not face any problems navigating to other pages or with javascript. Plus its Java. And there are a few questions that explain how to use Ghostdriver. – LittlePanda Apr 15 '15 at 07:42

0 Answers0