0

I wrote a script that generates an array of URLs. I want to open that URLs and extract the lowest price. I tried it with:

curl http://www.orbitz.com/shop/home?type=air&ar.rt.numAdult=1&ar.rt.numChild=0&_ar.rt.narrowSel=0&search=Search+Flights&ar.rt.child[2]=&ar.rt.leaveSlice.orig.key=las&strm=true&ar.rt.child[6]=&ar.rt.numSenior=0&ar.rt.narrow=airlines&ar.rt.carriers[2]=&ar.rt.cabin=C&_ar.rt.nonStop=0&ar.rt.child[3]=&ar.rt.child[7]=&_ar.rt.leaveSlice.originRadius=0&ar.rt.carriers[1]=&ar.rt.returnSlice.time=Anytime&ar.rt.child[4]=&ar.rt.child[0]=&_ar.rt.leaveSlice.destinationRadius=0&ar.rt.leaveSlice.time=Anytime&ar.rt.carriers[0]=&ar.rt.returnSlice.date=09%2F24%2F14&ar.rt.leaveSlice.date=09%2F23%2F14&ar.rt.leaveSlice.dest.key=lax&_ar.rt.flexAirSearch=0&ar.type=roundTrip&ar.rt.child[5]=&ar.rt.child[1]=|grep \"div class='basePrice '\"

but always get the whole content. I also tried it with various sed combinations and that didn't work, too. How can I just get the lowest price or at least a list of all prices?

2 Answers2

0

As a start you need to quote it properly:

curl 'http://www.orbitz.com/shop/home?type=air&ar.rt.numAdult=1&ar.rt.numChild=0&_ar.rt.narrowSel=0&search=Search+Flights&ar.rt.child[2]=&ar.rt.leaveSlice.orig.key=las&strm=true&ar.rt.child[6]=&ar.rt.numSenior=0&ar.rt.narrow=airlines&ar.rt.carriers[2]=&ar.rt.cabin=C&_ar.rt.nonStop=0&ar.rt.child[3]=&ar.rt.child[7]=&_ar.rt.leaveSlice.originRadius=0&ar.rt.carriers[1]=&ar.rt.returnSlice.time=Anytime&ar.rt.child[4]=&ar.rt.child[0]=&_ar.rt.leaveSlice.destinationRadius=0&ar.rt.leaveSlice.time=Anytime&ar.rt.carriers[0]=&ar.rt.returnSlice.date=09%2F24%2F14&ar.rt.leaveSlice.date=09%2F23%2F14&ar.rt.leaveSlice.dest.key=lax&_ar.rt.flexAirSearch=0&ar.type=roundTrip&ar.rt.child[5]=&ar.rt.child[1]=' | \
    grep "div class='basePrice '"

And perhaps your grep command is really meant to be:

grep 'div class="basePrice'
konsolebox
  • 72,135
  • 12
  • 99
  • 105
  • Is it working for you the `curl` command? it's giving me `curl: (3) [globbing] error: bad range specification after pos 129`. – rpax Jun 10 '14 at 17:30
  • It works with `curl -g '...'`. Unfortunately I don't get the prices as they are loaded about 20 seconds after calling the URL. Is there a way to let curl wait for a few seconds? – user3726817 Jun 11 '14 at 20:24
  • I'm not sure but perhaps [curl can't do that](http://stackoverflow.com/a/14625970/445221). Or maybe you can try [this one](http://unix.stackexchange.com/a/94612/45197). – konsolebox Jun 11 '14 at 20:33
0

You should probably use an html parser over sed and grep for this.

http://blog.codinghorror.com/parsing-html-the-cthulhu-way/

daidoji70
  • 331
  • 4
  • 13