Python Forum

Full Version: web form help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I have a script i'm trying to modify. It's suppose to fill out a form, however the search form has changed and I don't know how to modify the script so it updates the new fields

basically it goes to reserveramerica and searches camp sites given the parameters you enter (url = camp page) (length of stay - how many nights) (site code = camp site number/code) and date. However they've changed it now where CA sites are posted on

It now asks for city, location/camp site name, type of camping, date and how many nights. When looking at the source, I dont know which form names I need to specify.

Any help would be deeply appreciated.

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 = "reserveamerica dot com/camping/nehalem-bay-state-park/r/" # url of your desired campground
lengthOfStay = "1" # how many days you plan to stay
siteCode = "" # the codes of your favorite camp sites here
date = "10/01/2017" # 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()