开发者

Why does mechanize list one form?

开发者 https://www.devze.com 2023-01-24 10:46 出处:网络
开发者_如何学GoIf you run the following program: import mechanize br = mechanize.Browser() br.open(\"http://hansardindex.ontla.on.ca/hansarde.asp\")
开发者_如何学Go

If you run the following program:

import mechanize

br = mechanize.Browser()
br.open("http://hansardindex.ontla.on.ca/hansarde.asp")
for f  in br.forms():
    print f.name

Only one line of output is printed. However if you visit the page there are many forms with names such as "DateFrom". Why does mechanize not list the other forms?


There is a difference between 'Forms' and 'Input'. A form can contain many input fields.
see http://www.w3schools.com/html/html_forms.asp

Mechanize is right there is only ONE form but with multiple input fields.

What you probably want to do is access the input fields by name. So for example setting the 'searchcontents' input field works like this:

form = forms[0]
form["searchcontents"] = "keyword"

for more information, please have a look at the mechanize documentation at http://wwwsearch.sourceforge.net/mechanize/forms.html

0

精彩评论

暂无评论...
验证码 换一张
取 消