#!/usr/bin/env python # Author: Matt Mayes, www.givegoodweb.com """ Apple Vacations' website is annoying because they tease you with an attractive rate on a package, but don't directly show you the dates where you can actually get that low rate. Instead, they present you with a select box of many departure options, and you have to select each one and wait for their incredibly slow site to load. This script take the page that shows the package date and price (the page you get after you select a departure date and click "book it"), only with the 'selectedBatchNumber' variable left blank in the URL's GET values. It parses the select list, pulling these batch numbers out, and then opens each in a new web browser window. REQUIREMENTS: BeautifulSoup """ import urllib2, webbrowser from BeautifulSoup import BeautifulSoup # this is the page with the available dates select box select_list_page = 'http://applevacations.com/special.do?command=handleSelectSpecial&categoryId=678&selectedSpecialId=124237++++++++++++&duration=4&batchString=1407651+++%241407655+++%241407645+++%241407664+++%241407646+++%241407656+++%241407663+++%241407644+++%241407643+++%241407654+++%241407653+++%241407662+++%241407661+++%241407665+++%241407657+++%241407650+++%241407668+++%241407660+++%241407669+++%241407647+++%241407659+++%241407667+++%241407666+++%241407649+++%241407648+++%241407658+++%241407652+++%24&inSortOrder=&selectedGateway=ORD&selectedDestination=MBJ&selectedSortOrder=' page = urllib2.urlopen(select_list_page) soup = BeautifulSoup(page) # This is the result page you get after selecting a date # I've stripped off the the selectedBatchNumber id at the end # (We'll append each one on next, and open the complete URL in our browser) url = 'http://applevacations.com/special.do?command=handleSearchSpecial&categoryId=678&selectedSpecialId=124237++++++++++++&duration=4&selectedGateway=ORD&selectedDestination=MBJ&scheduledAirSpecialFlag=Y&selectedHotelId=212594&hotelCode=Riu+Ocho+Rios&numberOfAdults=2&advancedSearchSelectionOptions.numberOfChildren=&advancedSearchSelectionOptions.childAge%281%29=1&advancedSearchSelectionOptions.childAge%282%29=1&advancedSearchSelectionOptions.childAge%283%29=1&advancedSearchSelectionOptions.childAge%284%29=1&advancedSearchSelectionOptions.childAge%285%29=1&advancedSearchSelectionOptions.childAge%286%29=1&selectedBatchNumber=' # Now we identify the select list that has the dates # Easy enough, the name of this select list is also selectedBatchNumber select = soup.find('select',{'name':"selectedBatchNumber"}) option_tags = select.findAll('option') # The 1st one has no value, so strip it out option_tags = option_tags[1:] # Now we loop through each value # webbrowser.open will attempt to identfy the default browser, # and open each page in a new window/tab for option in option_tags: webbrowser.open(url + option['value'].strip()) # Best to get a cup of coffee while all the pages load