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()
以上是我的代码。现在我希望它显示这个http://casesearch.courts.state.md.us/inquiry/processDisclaimer.jis的HTML,但它没有这样做而是返回同一页面的HTML。我不明白为什么?
答案 0 :(得分:1)
添加.items[0]
:
br.find_control(name="disclaimer").items[0].selected
更完整的代码段如下所示:
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()
答案 1 :(得分:0)
你正在跳过一些比特。我很惊讶它并没有爆炸。
reponse = br.submit()
print reponse.read()
应该是:
br.submit() # returns nothing
print br.response().read()