如寫在題目我不得不改變使用機械化一些輸入字段的值,但我沒有,只ID的名稱:/讓我們堅持這一點。Python的機械化更改不願透露姓名的輸入值(稱爲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()'正是這裏需要做的。問題是什麼?謝謝。 – alecxe
那麼不知何故,返回AttributeError的:HtmlForm控件實例沒有__call__方法,我不知道如何改變屬性:■ – windoo