views:

38

answers:

2
from  mechanize import *
import cookielib
from BeautifulSoup import BeautifulSoup

br = Browser()
br.open('http://casesearch.courts.state.md.us/inquiry/inquiry-index.jsp')
br.select_form(name="main")
br.find_control(name="disclaimer").selected = True
reponse = br.submit()
print reponse.read()

The Above is my code. Now I expect it to show the HTML of this http://casesearch.courts.state.md.us/inquiry/processDisclaimer.jis but it is not doing so instead returning the HTML of the same page. I do not get why?

A: 

You're skipping some bits. I'm surprised it's not exploding.

reponse = br.submit()
print reponse.read()

should be:

br.submit() # returns nothing
print br.response().read()
Oli
Smae result! It is returning the HTML but of the same page not of the page which is returned when page is submitted in browser.
Shubham
+1  A: 

Add .items[0]:

br.find_control(name="disclaimer").items[0].selected

A fuller code snippet looks like this:

import mechanize

br = mechanize.Browser()
br.open('http://casesearch.courts.state.md.us/inquiry/inquiry-index.jsp')
br.select_form(name="main")
br.find_control(name="disclaimer").items[0].selected = True
reponse = br.submit()
print reponse.read()
Tim McNamara
Thanks! :)It worked.
Shubham