Skip to content

Instantly share code, notes, and snippets.

@zigdon
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zigdon/d1d013cb1bd46cf3f275 to your computer and use it in GitHub Desktop.
Save zigdon/d1d013cb1bd46cf3f275 to your computer and use it in GitHub Desktop.
In [5]: br.open_local_file("/tmp/login.html")
Out[5]: <response_seek_wrapper at 0xb5fdd6ccL whose wrapped object = <closeable_response at 0xb5fdd54cL whose fp = <open file '/tmp/login.html', mode 'rb' at 0xb60395a0>>>
In [6]: br.response().read()
Out[6]: '<html> <form accept-charset="UTF-8" action="/session" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="FBxtTbNqV7yBDXGQmhUDkqZgdBJuH+0M0o+SLcs/8F8=" /></div> <fieldset>\n <p>\n <label for="nickname_or_email">Nickname or email address:</label><br/>\n <input class="text first" id="nickname_or_email" name="nickname_or_email" type="text" value="" />\n </p>\n <p>\n <label for="password">Password:</label><br/>\n <input class="text" id="password" name="password" type="password" value="" />\n </p>\n <p class="remember_me"><input id="remember_me" name="remember_me" type="checkbox" value="1" /> <label for="remember_me">Remember me on this computer, I&#x27;ll be back!</label></p>\n <p class="submit">\n <input name="commit" type="submit" value="Login" />\n <span class="processing"><img src="spinner.gif?v597522e400348c" /></span>\n </p>\n </fieldset>\n</form> <footer>\n</html>'
In [7]: br.forms()
Out[7]: <generator object __call__ at 0xb5fdbacc>
In [8]: br.forms
Out[8]: <bound method Browser.forms of <mechanize._mechanize.Browser instance at 0xb6083c6c>>
In [9]: br.select_form(nr=0)
In [10]: br.form.controls
Out[10]:
[<mechanize._form.HiddenControl instance at 0xb5fe9f4c>,
<mechanize._form.HiddenControl instance at 0xb5fe9f8c>,
<mechanize._form.CheckboxControl instance at 0xb5fe9fcc>,
<mechanize._form.SubmitControl instance at 0xb5fef04c>]
In [19]: print str(br.form)
<POST file:/session application/x-www-form-urlencoded
<HiddenControl(utf8=&#x2713;) (readonly)>
<HiddenControl(authenticity_token=FBxtTbNqV7yBDXGQmhUDkqZgdBJuH+0M0o+SLcs/8F8=) (readonly)>
<CheckboxControl(remember_me=[1])>
<SubmitControl(commit=Login) (readonly)>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment