Skip to content

Instantly share code, notes, and snippets.

@emilssolmanis
Created May 10, 2014 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emilssolmanis/d002f76554101ea7d473 to your computer and use it in GitHub Desktop.
Save emilssolmanis/d002f76554101ea7d473 to your computer and use it in GitHub Desktop.
Expedia result scraping
$('.segment-result').each(function(i, flightModule) {
function getText(selector) {
return $(selector, flightModule).text().trim().replace(/\s+/g, ' ');
}
var srcCode = getText('[data-test-id=departureAirportCode]');
var destCode = getText('[data-test-id=arrivalAirportCode]');
var srcTime = getText('[data-test-id=departureTime]');
var destTime = getText('[data-test-id=arrivalTime]');
var duration = getText('[data-test-id=duration]').replace(',', '');
var price = getText('.offer-price > span').replace(',', '');
var airliner = $('.image-well > img', flightModule).attr('src').split('/').pop().split('.')[0];
var stops = getText('[data-test-id=stops]');
console.log('%s, %s, %s, %s, %s, %s, %s, %s', srcCode, destCode, srcTime, destTime, duration, price, airliner, stops);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment