Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Scrape ReserveAmerica for Available Campsites
import os, sys, re, io, json, time
import mechanize
import pytz
import smtplib
import bs4
from datetime import datetime, timedelta
from pytz import timezone
from bs4 import BeautifulSoup
from email.mime.text import MIMEText
from datetime import date
# Configuration
url = "" # url of your desired campground
lengthOfStay = "2" # how many days you plan to stay
siteCode = "A01,A02" # the codes of your favorite camp sites here
date = "08/21/2015" # the date you want to check
# Create browser
br = mechanize.Browser()
# Browser options
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1);
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')];;
# Fill out form
br.form.set_all_readonly(False) # allow changing the .value of all controls
br.form["campingDate"] = date
br.form["lengthOfStay"] = lengthOfStay
br.form["siteCode"] = siteCode
response = br.submit()
# Scrape result
soup = BeautifulSoup(response, "html.parser")
table = soup.findAll("table", {"id": "shoppingitems"})
rows = table[0].findAll("tr", {"class": "br"})
hits = []
for row in rows :
cells = row.findAll("td")
l = len(cells)
label = cells[0].findAll("div",{"class": "siteListLabel"})[0].text
status = cells[l-1].text
if( status.startswith( 'available' ) ):
if( len(hits) > 0 ):
hdisplay = ', '.join(hits)
hsend = '\n'.join(hits)
print "%s : found available sites --> %s" % (date, hdisplay )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment