I want to use CasperJS to scrape this website: http://www.agoda.com/hotel-des-arts-saigon-mgallery-collection/hotel/ho-chi-minh-city-vn.html?checkin=2015-11-14&los=2&adults=2&childs=0&rooms=1
I want to make change to the currency options by CasperJS. However, the currency options are wrapped in <select></select>
tags which is not embedded in a form. When I then read the table, it shows prices with the old currency. The prices are loaded through AJAX when the currency is changed.
How can I do with CasperJS?
Here is my code:
var casper = require("casper").create({
verbose: true,
logLevel: 'error',
pageSettings: {
loadImages: false,
}
});
var utils = require('utils');
var url = 'http://www.agoda.com/hotel-des-arts-saigon-mgallery-collection/hotel/ho-chi-minh-city-vn.html?checkin=2015-11-14&los=4&adults=2&childs=0&rooms=1';
var names = [];
var prices = [];
var currency = [];
function getName() {
var rows = document.querySelectorAll('table#room-grid-table tbody tr td:first-child .info-container .room-name span');
return Array.prototype.map.call(rows, function(e) {
return e.innerHTML;
});
}
function getPrice() {
var price = document.querySelectorAll('table#room-grid-table tbody tr td:nth-child(3) .price span.sellprice');
return Array.prototype.map.call(price, function(e) {
return e.innerHTML;
});
}
casper.start(url, function() {
this.echo(this.getTitle());
});
casper.then(function() {
this.click('select[id="currency-options"]');
});
casper.then(function() {
this.click('option[value="AED"]');
});
casper.then(function() {
names = this.evaluate(getName);
prices = this.evaluate(getPrice);
});
casper.then(function() {
utils.dump(names);
utils.dump(prices);
})
casper.run();
Select box:
<select id="currency-options" data-selenium="room-currency">
<option value="AED">Arab Emirates Dirham (AED)</option>
<option value="ARS">Argentine Peso (ARS)</option>
...
<option value="USD" selected="">US Dollar (USD)</option>
</select>
Table:
<table id="room-grid-table">
<tbody data-selenium="room-tbody" data-prebook-url="/NewSite/en-us/Hotel/Prebook/929399">
<tr>
<td>...</td>
<td>...</td>
<td>
<div class="price" data-selenium="price">
<span class="currency" data-selenium="price-currency">USD</span>
<span class="crossout show-cor-tooltip">288.75</span>
<span class="sellprice">187.11</span>
</div>
</td>
</tr>
<tr>...</tr>
...
</tbody>
</table>