jjlee / mechanize

Stateful programmatic web browsing in Python, after Andy Lester's Perl module WWW::Mechanize .
http://wwwsearch.sourceforge.net/mechanize/
618 stars 123 forks source link

Can you use Mechanize to work with .net events / postbacks? #69

Open ghost opened 12 years ago

ghost commented 12 years ago

Hi.

We couldn't find a single example of using mechanize to submit .net forms. All examples we've seen so far uses pages or resources like

<a href="page.php.. <form action="/action/do"

and so on, but we need to log into a form that was made in .net. These are the controls if you view the source: <a id="AuthUC_btnLogin" class="button primary login" href="javascript:__doPostBack('AuthUC$btnLogin','')">Login</a>

We just want to know if Mechanize can work with .net and, if possible, maybe a link with a few examples or documentation on how to implement it.

Thank you.

Leonardo.

ghost commented 12 years ago

No one? :(

QQism commented 11 years ago

.NET Postback basically uses only one big form with POST to drive the site.

You can try this one

import mechanize
import cookielib

br = mechanize.Browser(factory=mechanize.RobustFactory())

br.set_cookiejar(cookielib.LWPCookieJar())
br.set_handle_equiv = True
br.set_handle_redirect = True
br.set_handle_referer = True
br.set_handle_robots = False

br.open('http://AnotherStupidAspNet.com')
br.select_form(nr=0) # there is only one form, no need to hesitate
br.form['username'] = 'myusername'
br.form['password'] = 'mypassword'
br.form['button'] = 'AuthUC_btnLogin' # **important**, it may change base on what **LINK** you actually want to click
br.submit()