python mechanize 与 selectcontrol 的问题

发布于 2024-11-27 18:46:44 字数 889 浏览 2 评论 0原文

可以从中进行选择

基本上,其中一个选择控件有一些“选项”,如果我使用,

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

为你鎻心 2024-12-04 18:46:44

通过这样做,您只能获得默认值。

save = br.form['ctl00$cph2$ddlCourseSection'] 
print save

要获得您必须使用的所有值,

save = br.form.possible_items('ctl00$cph2$ddlCourseSection')
print save

我没有测试它,但我认为它会起作用。

By doing this you only get the default value.

save = br.form['ctl00$cph2$ddlCourseSection'] 
print save

To get all values you have to use

save = br.form.possible_items('ctl00$cph2$ddlCourseSection')
print save

i didn't test it but i think it will work.

君勿笑 2024-12-04 18:46:44

在我看来,您正在尝试将多个值分配给单选表单字段。您必须进行多项选择才能成功完成此操作。星号表示选定的元素,非星号的项目是列表中的其他选项。您确定您使用的是多选框而不是普通选择框吗?该表单不允许您为单个选择选择多个值。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文