使用Mechanize(Python)填写表格
我想使用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()
希望能有所帮助。