Python Mechanize changing an unnamed input value (known identifier)

as it is written in the topic, I have to change the value of some input field using mechanization, but I don't have a name it's only id: / Let's stick to the dot.

This is what the form looks like:

<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>

      

What should I do? Populate PopupPassword using some value and then submit it?

My approach looks like this:

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()

      

I am looking forward to some solutions, thanks in advance.

+3


source to share


1 answer


find_control()

is exactly what you need here. Just don't call br.form

, this is not a function:



password_field = br.form.find_control(id="PopupPassword")
password_field.value = "something"

      

+5


source







All Articles