Submitting form using mechanize in python

I am trying to submit a form to in python, using the following code:

import urllib from bs4 import BeautifulSoup import mechanize import datetime   today ="%m/%d/%Y")  url = '' html = urllib.urlopen(url).read() soup = BeautifulSoup(html) viewstate = soup.find('input', {'id' : '__VIEWSTATE'})['value'] eventval = soup.find('input', {'id' : '__EVENTVALIDATION'})['value']  br = mechanize.Browser(factory=mechanize.RobustFactory())  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 form  br.select_form("aspnetForm")  br.form.set_all_readonly(False) br.form['__EVENTTARGET'] = '' br.form['__EVENTARGUMENT'] = '' br.form['__LASTFOCUS'] = '' br.form['__VIEWSTATE'] = viewstate br.form['__VIEWSTATEGENERATOR'] = '41AA5B91' br.form['__EVENTVALIDATION'] = eventval br.form['ctl00$MainContent$lbCommodity'] = ['401'] br.form['ctl00$MainContent$lbCountry'] = ['0:0'] br.form['ctl00$MainContent$ddlReportFormat'] = ['10'] br.find_control('ctl00$MainContent$cbxSumGrand').items[0].selected = True br.find_control('ctl00$MainContent$cbxSumKnown').items[0].selected = False br.form['ctl00$MainContent$rblOutputType'] = ['2'] br.form['ctl00$MainContent$tbStartDate'] = '01/01/1999' br.form['ctl00$MainContent$ibtnStart'] = '' br.form['ctl00$MainContent$tbEndDate'] = today br.form['ctl00$MainContent$ibtnEnd'] = '' br.form['ctl00$MainContent$rblColumnSelection'] = ['regular']     response = br.submit() 

The response I am getting is essentially just the html code of the site with the form filled out as expected. However, I was expecting an excel file (as I have selected OutputType value of 2)

I think I am missing something on the submission front. Could somebody shed some light on what I am missing?


Category: python Time: 2016-07-29 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.126 (s). 12 q(s)