【发布时间】:2015-02-20 03:16:07
【问题描述】:
正如主题中所写,我必须使用 mechanize 更改某些输入字段的值,但我没有它的名称,只有 id :/ 让我们直言不讳。
这是表单的外观:
<form id="Login" name="Login">
<div id="login-inputs-div">
<input id="Username" type="hidden" name="username"></input>
<input id="Password" type="hidden" name="password"></input>
<input id="PopupUsername" class="input-text input-text-gray" type="text" disabled="disabled" value="admin" maxlength="32" style="width:100px;"></input>
<input id="PopupPassword" class="input-text input-text-gray " type="password" maxlength="32" value="" style="width:100px;" placeholder="hasło"></input>
<input id="bt_authenticate" class="input-btn input-btn-orange translation Translations.general.btn.authenticate translated" type="submit" value="zaloguj"></input>
</div>
<div id="logout-link-div" style="display: none;"></div>
</form>
我必须做什么?使用一些值填写 PopupPassword 并稍后提交?
我的方法如下:
import mechanize
url = "http://192.168.1.1"
br = mechanize.Browser()
br.set_handle_robots(False)
br.open(url)
br.select_form(name="Login")
br.form().find_control(id="PopupPassword").__setattr__("value", "something")
res = br.submit()
content = res.read()
我期待一些解决方案,在此先感谢。
【问题讨论】:
-
使用
find_control()正是这里需要做的。问题是什么?谢谢。 -
它以某种方式返回 AttributeError: HTMLForm instance has no call 方法,我不知道如何更改属性:s
标签: python html forms mechanize