gpt4 book ai didi

python Mechanize 刹车TextareaControl的内容

转载 作者:行者123 更新时间:2023-12-04 16:22:49 25 4
gpt4 key购买 nike

我想在 [OSQA > 用户设置] 的管理面板中更改一个复选框,但是当我使用 Mechanize 提交 Web 表单时,它会使用其他字符粉碎 TextareaControl 的内容。

>>> import mechanize
>>> mech = mechanize.Browser()
>>> mech.open('http://example.com/account/signin/')
>>> mech.select_form(nr=2)
>>> mech["username"] = 'user'
>>> mech["password"] = 'pass'

>>> mech.open('http://example.com/admin/settings/users/')
>>> for el in mech.forms():
... print el
...
<POST http://example.com/admin/settings/users/ multipart/form-data
<HiddenControl(csrfmiddlewaretoken=XxWchtzV5oR6ezkObhnk4nzIemTc8aDC) (readonly)>
<TextControl(MIN_USERNAME_LENGTH=3)>
<TextareaControl(RESERVED_USERNAMES=testing, this)> # << HERE
<CheckboxControl(TRUNCATE_LONG_USERNAMES=[*on])>
<CheckboxControl(SHOW_USER_ACCEPT_RATE=[*on])>
<TextControl(FREEZE_ACCEPT_RATE_FOR=admin)>
<SubmitControl(submit=Save) (readonly)>>

>>> mech.select_form(nr=0)
>>> print mech["RESERVED_USERNAMES"]
... testing, this

所以当我现在提交它甚至没有修改任何字段时......
>>> results = mech.submit()

... TextareaControl 的内容变为:
>>> mech.open('http://example.com/admin/settings/users/')
>>> mech.select_form(nr=0)
>>> print mech["RESERVED_USERNAMES"]
... t, ,, , e, ,, , s, ,, , t, ,, , i, ,, , n, ,, , g, ,, , ,, ,, , , ,, , t, ,, , h, ,, , i, ,, , s

最佳答案

试图调试 Mechanize 但没有运气。

我最终通过在 osqa/forum/settings/users.py 中安装之前更改 OSQA 设置来选择这些复选框。

REQUIRE_EMAIL_VALIDATION_TO = Setting('REQUIRE_EMAIL_VALIDATION_TO', [], USERS_SET, dict(
label = _("Require email validation to..."),
help_text = _("Which actions in this site, users without a valid email will be prevented from doing."),
widget=CheckboxSelectMultiple(attrs={"checked":"checked"}),
choices=(("ask", _("ask questions")), ("answer", _("provide answers")), ("comment", _("make comments")), ("flag", _("report posts"))),
required=False,
))

已添加 (attrs={"checked":"checked"}) ,这不是我想要的,但解决了我的问题。

关于python Mechanize 刹车TextareaControl的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36735731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com