python mechanize 与 selectcontrol 的问题
可以从中进行选择
基本上,其中一个选择控件有一些“选项”,如果我使用,
for t in br.forms():
print t
:我得到的输出
`SelectControl(ctl00$cph2$ddlSchool=[*2])
SelectControl(ctl00$cph2$ddlMarkingPeriod=[*1, 2, 3, 4])
SelectControl(ctl00$cph2$ddlCourseSection=[*1120:01:1, 1515:01:1, 2445:01:1, 3723:02:1, 4140:03:1, 5100:08:1, 1:01:1, 9970:07:1, 9913:01:1])>
SubmitControl(ctl00$cph2$btnExecuteReport=Execute) (readonly)`
现在注意星号
,我想要的是将列表存储在我的程序中的“ctl00$cph2$ddlCourseSection”下但是如果我尝试存储它然后打印它:
save = br.form['ctl00$cph2$ddlCourseSection']
print save
我得到的输出是:
['1120:01:1']
而不是:
['1120:01:1', '1515:01:1', '2445:01:1', '3723:02:1', '4140:03:1', '5100:08:1', '1:01:1', '9970:07:1', '9913:01:1']
那么我如何能够保存列表的所有元素,而不仅仅是旁边带有星号的元素?
basically one of the select controls has a few "options" in which to choose from
if i use:
for t in br.forms():
print t
the output i get is
`SelectControl(ctl00$cph2$ddlSchool=[*2])
SelectControl(ctl00$cph2$ddlMarkingPeriod=[*1, 2, 3, 4])
SelectControl(ctl00$cph2$ddlCourseSection=[*1120:01:1, 1515:01:1, 2445:01:1, 3723:02:1, 4140:03:1, 5100:08:1, 1:01:1, 9970:07:1, 9913:01:1])>
SubmitControl(ctl00$cph2$btnExecuteReport=Execute) (readonly)`
notice the asterisks
now, what i want is to store the list under "ctl00$cph2$ddlCourseSection" in my program but if i try and store it and then print it:
save = br.form['ctl00$cph2$ddlCourseSection']
print save
the output i get is:
['1120:01:1']
instead of:
['1120:01:1', '1515:01:1', '2445:01:1', '3723:02:1', '4140:03:1', '5100:08:1', '1:01:1', '9970:07:1', '9913:01:1']
so how would i be able to save all of the elements of the list rather than just the element with the asterisk next to it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过这样做,您只能获得默认值。
要获得您必须使用的所有值,
我没有测试它,但我认为它会起作用。
By doing this you only get the default value.
To get all values you have to use
i didn't test it but i think it will work.
在我看来,您正在尝试将多个值分配给单选表单字段。您必须进行多项选择才能成功完成此操作。星号表示选定的元素,非星号的项目是列表中的其他选项。您确定您使用的是多选框而不是普通选择框吗?该表单不允许您为单个选择选择多个值。
It looks to me like you're trying to assign multiple values to a single-select form field. You would have to have a multi-select to do that successfully. The asterisk indicates the selected element, the non-asterisk'd items are the other options in the list. Are you sure that you are working with a multi-select and not a normal select box? The form will not allow you to select multiple values for a single select.