如果控件名称为None
,我一直在使用this问题作为如何更改表单控件的指南。我做到了这一点:
basket = br.open('http://www.numbeo.com/cost-of-living/city_result.jsp')
read_it = basket.read()
br.form = list(br.forms())[0]
br.set_value("put_city_here", nr=1)
for control in br.form.controls:
print control
print ' ', "type=%s, name=%s" % (control.type, control.name)
br.form["put_city_here"] = 'New York'
br.submit()
在我尝试更改控件之前,这就是控件的样子:
<HiddenControl(where=http://www.numbeo.com/cost-of-living/city_result.jsp) (readonly)>
type=hidden, name=where
<TextControl(<None>=)> #Control that I'm interested in
type=text, name=None
<HiddenControl(city_id=) (readonly)>
type=hidden, name=city_id
<HiddenControl(name_city_id=) (readonly)>
type=hidden, name=name_city_id
之后:
<HiddenControl(where=http://www.numbeo.com/cost-of-living/city_result.jsp) (readonly)>
type=hidden, name=where
<TextControl(<None>=put_city_here)> #Control that I'm interested in
type=text, name=None
<HiddenControl(city_id=) (readonly)>
type=hidden, name=city_id
<HiddenControl(name_city_id=) (readonly)>
type=hidden, name=name_city_id
我不知道我需要做什么来控制名称,而不是控件代表什么,才能改变。谢谢你的帮助。