Created
October 29, 2014 02:10
-
-
Save peterskipper/eb065e65b163b3bdcf60 to your computer and use it in GitHub Desktop.
Airfare Watchdog web scrape
This file contains hidden or 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
import mechanize | |
from BeautifulSoup import BeautifulSoup | |
URL = "http://www.airfarewatchdog.com/" | |
def input_destination(dest): | |
br = mechanize.Browser() | |
br.open(URL) | |
formcount = 0 | |
for form in br.forms(): | |
if str(form.attrs['id']) == 'fares_search_fromto_form': | |
break | |
formcount += 1 | |
br.select_form(nr=formcount) | |
br["city_dep"] = dest | |
return br.submit().read() | |
def scrape_results(form_data): | |
soup = BeautifulSoup(form_data) | |
result = soup.findAll("tr", {"class": ["o", "e"]}) #classes of airfare data when I submit form manually | |
if __name__ == "__main__": | |
response = input_destination("LAX") | |
print response | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment