Skip to content

Instantly share code, notes, and snippets.

@lost-theory
Created July 26, 2015 04:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lost-theory/08786e3a27c8d8ce3839 to your computer and use it in GitHub Desktop.
Save lost-theory/08786e3a27c8d8ce3839 to your computer and use it in GitHub Desktop.
'''
http://stackoverflow.com/questions/31632461/can-mechanize-support-ajax-filling-out-forms-via-javascript/
'''
import urllib.parse, urllib.request
URL = "https://interactive.web.insurance.ca.gov/survey/survey?type=homeownerSurvey&event=HOMEOWNERS"
LOCATIONS = '''
ALAMEDA ALAMEDA
ALAMEDA BERKELEY
ALAMEDA FREMONT
ALAMEDA HAYWARD
ALAMEDA LIVERMORE
ALAMEDA OAKLAND - Piedmont
'''.strip().split('\n')
def get_premiums(location, coverage_type, coverage_amt, home_age):
data = urllib.parse.urlencode(dict(
location=location,
coverageType=coverage_type,
coverageAmount=coverage_amt,
homeAge=home_age,
))
res = urllib.request.urlopen(URL, data.encode("utf8"))
return res.read()
def main():
for location in LOCATIONS:
p = get_premiums(location, "HOMEOWNERS", "150000", "New")
#do something with `p`
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment