Created
December 22, 2012 01:27
-
-
Save devyfriend/4356939 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var casper = require('casper').create({ | |
clientScripts: ["c:/phantomjs/casperjs/includes/jquery.js"] | |
}); | |
var cnt = 0, tots = 666; | |
var param = { | |
'duration[from]':115, | |
'duration[to]':375, | |
'numberOfFlights':300, | |
'filter':'both', | |
'filterAirline[]':['Garuda','Merpati'], | |
'searchTask':'search',//'change_filter', | |
'searchToken':'searchSession_b0339c6584e8519c5378e302a958821e', | |
'times[dep][landing][from]':0, | |
'times[dep][landing][to]':1439, | |
'times[dep][takeOff][from]':0, | |
'times[dep][takeOff][to]':1439, | |
'times[ret][landing][from]':0, | |
'times[ret][landing][to]':1439, | |
'times[ret][takeOff][from]':0, | |
'times[ret][takeOff][to]':1439, | |
'visible':300 | |
}; | |
casper.start('http://www.tiket2.com/indonesia/search/CGK-BPN-2012-12-28-2013-01-04-1.html'); | |
casper.then(function(){ | |
this.open('http://www.tiket2.com/indonesia/search/CGK-BPN-2012-12-28-2013-01-04-1.html', { | |
method: 'post',headers: {'X-Requested-With': 'XMLHttpRequest'}, | |
data: param //'duration%5Bfrom%5D=115&duration%5Bto%5D=375&filter=both&filterAirline%5B%5D=Merpati&filterAirline%5B%5D=Garuda&searchTask=search&searchToken=searchSession_b0339c6584e8519c5378e302a958821e×%5Bdep%5D%5Blanding%5D%5Bfrom%5D=0×%5Bdep%5D%5Blanding%5D%5Bto%5D=1439×%5Bdep%5D%5BtakeOff%5D%5Bfrom%5D=0×%5Bdep%5D%5BtakeOff%5D%5Bto%5D=1439×%5Bret%5D%5Blanding%5D%5Bfrom%5D=0×%5Bret%5D%5Blanding%5D%5Bto%5D=1439×%5Bret%5D%5BtakeOff%5D%5Bfrom%5D=0×%5Bret%5D%5BtakeOff%5D%5Bto%5D=1439&visible=0' //&numberOfFlights=0&filterAirline%5B%5D=Sriwijaya' | |
}); | |
}).then(function(){ | |
param.searchTask = 'change_filter'; | |
this.open('http://www.tiket2.com/indonesia/search/CGK-BPN-2012-12-28-2013-01-04-1.html', { | |
method: 'post',headers: {'X-Requested-With': 'XMLHttpRequest'}, | |
data: param //'duration%5Bfrom%5D=115&duration%5Bto%5D=375&filter=both&filterAirline%5B%5D=Merpati&filterAirline%5B%5D=Garuda&searchTask=search&searchToken=searchSession_b0339c6584e8519c5378e302a958821e×%5Bdep%5D%5Blanding%5D%5Bfrom%5D=0×%5Bdep%5D%5Blanding%5D%5Bto%5D=1439×%5Bdep%5D%5BtakeOff%5D%5Bfrom%5D=0×%5Bdep%5D%5BtakeOff%5D%5Bto%5D=1439×%5Bret%5D%5Blanding%5D%5Bfrom%5D=0×%5Bret%5D%5Blanding%5D%5Bto%5D=1439×%5Bret%5D%5BtakeOff%5D%5Bfrom%5D=0×%5Bret%5D%5BtakeOff%5D%5Bto%5D=1439&visible=0' //&numberOfFlights=0&filterAirline%5B%5D=Sriwijaya' | |
}); | |
tots = this.getHTML('#response'); | |
}); | |
/* | |
casper.evaluate(function(){ | |
__utils__.echo(tots); | |
elements = $(tots).find('div.flightRow'); | |
var _cnt = 1; | |
var tmp = []; | |
$.each(elements,function(ix,el){ | |
var pr = $(el).find('.wrapperPrice p em.sortonthis')[0].innerText; | |
var fl = $(el).find('.airlineLogo div')[0].innerText; | |
_cnt = ++ix; | |
this.echo( _cnt +'. '+fl+' - '+pr ); | |
}); | |
}); | |
*/ | |
casper.run(function(){ | |
//tots = this.getHTML(); | |
this.evaluate(function(){ | |
__utils__.echo(tots); | |
}); | |
//this.echo($(tots).find('#percents')[0].innerHTML); | |
this.exit(); | |
}); | |
/* | |
casper.then(function(){ | |
this.open('http://www.tiket2.com/indonesia/search/CGK-BPN-2012-12-28-2013-01-04-1.html', { | |
method: 'post',headers: {'X-Requested-With': 'XMLHttpRequest'}, | |
data: 'duration%5Bfrom%5D=115&duration%5Bto%5D=375&filter=both&filterAirline%5B%5D=Merpati&filterAirline%5B%5D=Garuda&searchTask=change_filter&searchToken=searchSession_b0339c6584e8519c5378e302a958821e×%5Bdep%5D%5Blanding%5D%5Bfrom%5D=0×%5Bdep%5D%5Blanding%5D%5Bto%5D=1439×%5Bdep%5D%5BtakeOff%5D%5Bfrom%5D=0×%5Bdep%5D%5BtakeOff%5D%5Bto%5D=1439×%5Bret%5D%5Blanding%5D%5Bfrom%5D=0×%5Bret%5D%5Blanding%5D%5Bto%5D=1439×%5Bret%5D%5BtakeOff%5D%5Bfrom%5D=0×%5Bret%5D%5BtakeOff%5D%5Bto%5D=1439&visible=0' //&numberOfFlights=0&filterAirline%5B%5D=Sriwijaya' | |
}); | |
}); | |
casper.then(function(){ | |
this.open('http://www.tiket2.com/indonesia/search/CGK-BPN-2012-12-28-2013-01-04-1.html', { | |
method: 'post',headers: {'X-Requested-With': 'XMLHttpRequest'}, | |
data: 'duration%5Bfrom%5D=115&duration%5Bto%5D=375&filter=both&filterAirline%5B%5D=Merpati&filterAirline%5B%5D=Garuda&searchTask=change_filter&searchToken=searchSession_b0339c6584e8519c5378e302a958821e×%5Bdep%5D%5Blanding%5D%5Bfrom%5D=0×%5Bdep%5D%5Blanding%5D%5Bto%5D=1439×%5Bdep%5D%5BtakeOff%5D%5Bfrom%5D=0×%5Bdep%5D%5BtakeOff%5D%5Bto%5D=1439×%5Bret%5D%5Blanding%5D%5Bfrom%5D=0×%5Bret%5D%5Blanding%5D%5Bto%5D=1439×%5Bret%5D%5BtakeOff%5D%5Bfrom%5D=0×%5Bret%5D%5BtakeOff%5D%5Bto%5D=1439&visible=0' //&numberOfFlights=0&filterAirline%5B%5D=Sriwijaya' | |
}); | |
tots = this.evaluate(function(){ | |
return __utils__.exists('#search-flights-count'); | |
}); | |
}); | |
casper.run(function(){ | |
this.echo(tots).exit(); | |
}) | |
casper.then(function(){ | |
this.open('http://www.tiket2.com/indonesia/search/CGK-BPN-2012-12-28-2013-01-04-1.html', { | |
method: 'post',headers: {'X-Requested-With': 'XMLHttpRequest'}, | |
data: 'duration%5Bfrom%5D=115&duration%5Bto%5D=375&filter=both&filterAirline%5B%5D=Merpati&filterAirline%5B%5D=Garuda&searchTask=more&searchToken=searchSession_b0339c6584e8519c5378e302a958821e×%5Bdep%5D%5Blanding%5D%5Bfrom%5D=0×%5Bdep%5D%5Blanding%5D%5Bto%5D=1439×%5Bdep%5D%5BtakeOff%5D%5Bfrom%5D=0×%5Bdep%5D%5BtakeOff%5D%5Bto%5D=1439×%5Bret%5D%5Blanding%5D%5Bfrom%5D=0×%5Bret%5D%5Blanding%5D%5Bto%5D=1439×%5Bret%5D%5BtakeOff%5D%5Bfrom%5D=0×%5Bret%5D%5BtakeOff%5D%5Bto%5D=1439&visible=0' //&filterAirline%5B%5D=Sriwijaya' | |
}); | |
}); | |
casper.then(function(){ | |
var _cnt = 1 | |
var data = this.evaluate(function(){ | |
elements = __utils__.findAll('div.flightRow'); | |
var tmp = []; | |
$.each(elements,function(ix,el){ | |
var pr = $(el).find('.wrapperPrice p em.sortonthis')[0].innerText; | |
var fl = $(el).find('.airlineLogo div')[0].innerText; | |
_cnt = ++ix; | |
tmp.push( _cnt +'. '+fl+' - '+pr ); | |
}); | |
return tmp; | |
}); | |
this.echo(data.join('\r\n')); | |
}); | |
*/ | |
/*.then(function(){ | |
this.open('http://www.tiket2.com/indonesia/search/CGK-BPN-2012-12-28-2013-01-04-1.html', { | |
method: 'post', | |
headers: { | |
'X-Requested-With': 'XMLHttpRequest' | |
}, | |
data: 'duration%5Bfrom%5D=115&duration%5Bto%5D=375&filter=both&filterAirline%5B%5D=Merpati&filterAirline%5B%5D=Garuda&searchTask=change_filter&searchToken=test×%5Bdep%5D%5Blanding%5D%5Bfrom%5D=0×%5Bdep%5D%5Blanding%5D%5Bto%5D=1439×%5Bdep%5D%5BtakeOff%5D%5Bfrom%5D=0×%5Bdep%5D%5BtakeOff%5D%5Bto%5D=1439×%5Bret%5D%5Blanding%5D%5Bfrom%5D=0×%5Bret%5D%5Blanding%5D%5Bto%5D=1439×%5Bret%5D%5BtakeOff%5D%5Bfrom%5D=0×%5Bret%5D%5BtakeOff%5D%5Bto%5D=1439&visible=0&filterAirline%5B%5D=Sriwijaya' | |
}); | |
}); | |
var _cnt = 0; | |
var data = this.evaluate(function(){ | |
elements = __utils__.findAll('div.flightRow'); | |
var tmp = []; | |
$.each(elements,function(ix,el){ | |
var pr = $(el).find('.wrapperPrice p em.sortonthis')[0].innerText; | |
var fl = $(el).find('.airlineLogo div')[0].innerText; | |
_cnt = ++ix; | |
tmp.push( _cnt +'. '+fl+' - '+pr ); | |
}); | |
return tmp; | |
}); | |
}); | |
*/ | |
/*.then(function(){ | |
this.open('http://www.tiket2.com/indonesia/search/CGK-BPN-2012-12-28-2013-01-04-1.html', { | |
method: 'post', | |
headers: { | |
'X-Requested-With': 'XMLHttpRequest' | |
}, | |
data: 'duration%5Bfrom%5D=115&duration%5Bto%5D=375&filter=both&filterAirline%5B%5D=Sriwijaya&filterAirline%5B%5D=Merpati&filterAirline%5B%5D=Garuda&searchTask=more&searchToken=test×%5Bdep%5D%5Blanding%5D%5Bfrom%5D=0×%5Bdep%5D%5Blanding%5D%5Bto%5D=1439×%5Bdep%5D%5BtakeOff%5D%5Bfrom%5D=0×%5Bdep%5D%5BtakeOff%5D%5Bto%5D=1439×%5Bret%5D%5Blanding%5D%5Bfrom%5D=0×%5Bret%5D%5Blanding%5D%5Bto%5D=1439×%5Bret%5D%5BtakeOff%5D%5Bfrom%5D=0×%5Bret%5D%5BtakeOff%5D%5Bto%5D=1439&visible=30&numberOfFlights=30' | |
}); | |
var _cnt = 0; | |
var data = this.evaluate(function(){ | |
elements = __utils__.findAll('div.flightRow'); | |
var tmp = []; | |
$.each(elements,function(ix,el){ | |
var pr = $(el).find('.wrapperPrice p em.sortonthis')[0].innerText; | |
var fl = $(el).find('.airlineLogo div')[0].innerText; | |
_cnt = ++ix; | |
tmp.push( _cnt +'. '+fl+' - '+pr ); | |
}); | |
return tmp; | |
}); | |
cnt = _cnt; | |
var fs = require('fs'); | |
fs.write('myfile.txt', data.join('\r\n'), 'w'); | |
}); | |
*/ | |
//casper.run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment