我想使用 python mechanize 填写此页面上的表格,然后记录响应。我应该怎么做?当我使用以下代码在此页面上搜索表单时,它仅显示用于搜索的表单。我应该如何找到其他表格的表格名称以及姓名,性别等字段?
http://aapmaharashtra.org/join-us
代码:
import mechanize
br=mechanize.Browser()
br.open("http://aapmaharashtra.org/join-us")
for form in br.forms():
print "Form name:", form.name
print form
最佳答案
您需要的表单(带有 id="form1"
)是动态加载的 - 这就是为什么您在 select_forms()
中看不到它的原因> 结果。
通过使用浏览器开发人员工具,您可能会发现表单是从 http://internal.aamaadmiparty.org/Directory/Format.aspx?master=blank
链接加载的。
那么你应该从这里开始:
import mechanize
br = mechanize.Browser()
br.open("http://internal.aamaadmiparty.org/Directory/Format.aspx?master=blank")
br.select_form(nr=0)
br.form['ctl00$MainContent$txtname'] = 'Test Name'
# fill out other fields
req = br.submit()
希望对您有所帮助。
关于python - 使用 Mechanize (Python) 填写表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22294489/