title: log in with browser and then ruby/mechanize takes it over?
body: <p>Is that even possible? what I need to pass to mechanize? With what url I can start then?</p>
  
  <p>I cannot manage (so far) to log into one website using mechanize so I was thinking if I can do this little workaround. I believe I can capture all cookies and everything else and then pass it to ruby/mechanize to do the rest ...</p>
  
  <p>screenshots below are made using firebug ( <a href="http://www.google.com/search?hl=en&amp;q=%22Firebug+logs+the+POST+or+GET+request%2C+the+response+headers+and+the+raw+text+of+the+response%22&amp;aq=f&amp;aqi=&amp;oq=" rel="nofollow noreferrer">Firebug logs the POST or GET request, the response headers</a> )</p>
  
  <p>login that works = just one line</p>
  
  <p><a href="https://i.stack.imgur.com/yiOMG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yiOMG.png" alt="login that works = just one line"></a>
  </p>
  
  <p>and html for login that works</p>
  
  <p>
            </p>
  
  <pre><code>        &lt;script type="text/javascript" src="clientscript/vbulletin_md5.js?v=3612"&gt;&lt;/script&gt;
                      &lt;table cellpadding="0" cellspacing="1" border="0"&gt;
                      &lt;tr&gt;
                          &lt;td class="smallfont" align="left"&gt;&lt;label for="navbar_username"&gt;User Name&lt;/label&gt;&lt;/td&gt;
                          &lt;td class="smallfont" align="left" colspan="2"&gt;&lt;label for="navbar_password"&gt;Password&lt;/label&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
  
                          &lt;td&gt;&lt;input type="text" class="button" name="vb_login_username" id="navbar_username" size="10" accesskey="u" tabindex="101" value="User Name" onfocus="if (this.value == 'User Name') this.value = '';" /&gt;&lt;/td&gt;        
                          &lt;td&gt;&lt;input type="password" class="button" name="vb_login_password" id="navbar_password" size="10" accesskey="p" tabindex="102" /&gt;&lt;/td&gt;
                          &lt;td class="smallfont" align="left" valign="middle"&gt;&lt;input type="submit" class="button" value="Log in" tabindex="103" title="Enter your username and password in the boxes provided to login, or click the 'register' button to create a profile for yourself." accesskey="s" /&gt;
                              &lt;label for="cb_cookieuser_navbar"&gt;
                              &lt;input type="checkbox" name="cookieuser" value="1" tabindex="103" id="cb_cookieuser_navbar" accesskey="c" /&gt;Save?&lt;/label&gt;
                              &lt;input type="hidden" name="s" value="" /&gt;
  &lt;input type="hidden" name="securitytoken" value="1cbc0286417d97b4eb43ee0b0c2b54e7c615e5b8" /&gt;
                              &lt;input type="hidden" name="do" value="login" /&gt;
                              &lt;input type="hidden" name="vb_login_md5password" /&gt;
  
                              &lt;input type="hidden" name="vb_login_md5password_utf" /&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;/table&gt;
        &lt;/form&gt;
        &lt;!-- / login form --&gt;
  </code></pre>
  
  <p>login that doesn't work for me</p>
  
  <p><a href="https://i.stack.imgur.com/v3ui9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/v3ui9.png" alt="login that doesn&#39;t work for me"></a>
  </p>
  
  <p>and it's html </p>
  
  <pre><code>&lt;form class="login" method="post"&gt; &lt;fieldset&gt;
  &lt;legend&gt;Members Login&lt;/legend&gt; 
  
  &lt;div&gt;
  &lt;label for="auth_username"&gt;Username&lt;/label&gt; &lt;input id="auth_username" name="auth_username"&gt;
  &lt;/div&gt;
  
  &lt;div&gt;
  &lt;label for="auth_password"&gt;Password&lt;/label&gt; &lt;input id="auth_password" name="auth_password" type="password"&gt;
  &lt;/div&gt;
  
  &lt;/fieldset&gt;
  &lt;div class="buttons"&gt;
  &lt;input name="auth_login" type="submit" value="Login"&gt;&lt;p class="note"&gt;&lt;a href="/forgotpassword"&gt;Forgot your password?&lt;/a&gt;&lt;/p&gt;
  
  &lt;/div&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>my script is almost the same in both cases. </p>
  
  <pre><code>require 'rubygems'
  require 'mechanize'
  #agent = WWW::Mechanize.new
  
  agent = WWW::Mechanize.new 
  
  page = agent.get("http://www.vbulletin.org/forum/index.php")
  
  login_form = page.form_with(:action =&gt; 'login.php?do=login')
  
  
  puts 
  login_form.fields.each { |f| puts "#{f.name} : #{f.value}" }    
  login_form['vb_login_username'] = 'user name'
  login_form['vb_login_password'] = ''
  
  page = agent.submit login_form
  
  output = File.open("login.html", "w") {|f| f.write(page.parser.to_html) }
  </code></pre>
  
  <p>mechanize log for the login that doesn't work</p>
  
  <pre><code> INFO -- : Net::HTTP::Get: /login?auth_successurl=http://www.somedomain.com/forum/yota?baz_r=1
  DEBUG -- : request-header: accept-language =&gt; en-us,en;q=0.5
  DEBUG -- : request-header: connection =&gt; keep-alive
  DEBUG -- : request-header: accept =&gt; */*
  DEBUG -- : request-header: accept-encoding =&gt; gzip,identity
  DEBUG -- : request-header: user-agent =&gt; WWW-Mechanize/0.9.3 (http://rubyforge.org/projects/mechanize/)
  DEBUG -- : request-header: accept-charset =&gt; ISO-8859-1,utf-8;q=0.7,*;q=0.7
  DEBUG -- : request-header: host =&gt; www.somedomain.com
  DEBUG -- : request-header: keep-alive =&gt; 300
  DEBUG -- : Read 400 bytes
  DEBUG -- : Read 1424 bytes
  DEBUG -- : Read 2448 bytes
  DEBUG -- : Read 3211 bytes
  DEBUG -- : response-header: vary =&gt; Accept-Encoding
  DEBUG -- : response-header: cache-control =&gt; no-store, no-cache, must-revalidate, post-check=0, pre-check=0
  DEBUG -- : response-header: connection =&gt; close
  DEBUG -- : response-header: expires =&gt; Thu, 19 Nov 1981 08:52:00 GMT
  DEBUG -- : response-header: content-type =&gt; text/html; charset=utf-8
  DEBUG -- : response-header: date =&gt; Fri, 29 Jan 2010 23:43:12 GMT
  DEBUG -- : response-header: content-encoding =&gt; gzip
  DEBUG -- : response-header: server =&gt; Apache/2.2.3 (CentOS)
  DEBUG -- : response-header: content-length =&gt; 3211
  DEBUG -- : response-header: set-cookie =&gt; PHPSESSID=7cfilg86ju2ldcgso22246hpu4; path=/, WebStats:visitorId=lSMkcwuSWEE%3D; expires=Mon, 27-Jan-2020 23:43:12 GMT; path=/, WebStats:sessionId=%2B2HHK296t%2BQ%3D; expires=Mon, 27-Jan-2020 23:43:12 GMT; path=/
  DEBUG -- : response-header: accept-ranges =&gt; bytes
  DEBUG -- : response-header: pragma =&gt; no-cache
  DEBUG -- : gunzip body
  DEBUG -- : saved cookie: PHPSESSID=7cfilg86ju2ldcgso22246hpu4
  DEBUG -- : saved cookie: WebStats:visitorId=lSMkcwuSWEE%3D
  DEBUG -- : saved cookie: WebStats:sessionId=%2B2HHK296t%2BQ%3D
   INFO -- : status: 200
  DEBUG -- : query: "auth_username=radek&amp;auth_password=mypassword"
   INFO -- : Net::HTTP::Post: /login?auth_successurl=http://www.somedomain.com/forum/yota?baz_r=1
  DEBUG -- : request-header: accept-language =&gt; en-us,en;q=0.5
  DEBUG -- : request-header: connection =&gt; keep-alive
  DEBUG -- : request-header: accept =&gt; */*
  DEBUG -- : request-header: accept-encoding =&gt; gzip,identity
  DEBUG -- : request-header: content-type =&gt; application/x-www-form-urlencoded
  DEBUG -- : request-header: user-agent =&gt; WWW-Mechanize/0.9.3 (http://rubyforge.org/projects/mechanize/)
  DEBUG -- : request-header: cookie =&gt; WebStats:sessionId=%2B2HHK296t%2BQ%3D; WebStats:visitorId=lSMkcwuSWEE%3D; PHPSESSID=7cfilg86ju2ldcgso22246hpu4
  DEBUG -- : request-header: referer =&gt; http://www.somedomain.com/login?auth_successurl=http://www.somedomain.com/forum/yota?baz_r=1
  DEBUG -- : request-header: accept-charset =&gt; ISO-8859-1,utf-8;q=0.7,*;q=0.7
  DEBUG -- : request-header: content-length =&gt; 43
  DEBUG -- : request-header: host =&gt; www.somedomain.com
  DEBUG -- : request-header: keep-alive =&gt; 300
  DEBUG -- : Read 650 bytes
  DEBUG -- : Read 1674 bytes
  DEBUG -- : Read 2698 bytes
  DEBUG -- : Read 3211 bytes
  DEBUG -- : response-header: vary =&gt; Accept-Encoding
  DEBUG -- : response-header: cache-control =&gt; no-store, no-cache, must-revalidate, post-check=0, pre-check=0
  DEBUG -- : response-header: connection =&gt; close
  DEBUG -- : response-header: expires =&gt; Thu, 19 Nov 1981 08:52:00 GMT
  DEBUG -- : response-header: content-type =&gt; text/html; charset=utf-8
  DEBUG -- : response-header: date =&gt; Fri, 29 Jan 2010 23:43:13 GMT
  DEBUG -- : response-header: content-encoding =&gt; gzip
  DEBUG -- : response-header: server =&gt; Apache/2.2.3 (CentOS)
  DEBUG -- : response-header: content-length =&gt; 3211
  DEBUG -- : response-header: accept-ranges =&gt; bytes
  DEBUG -- : response-header: pragma =&gt; no-cache
  DEBUG -- : gunzip body
   INFO -- : status: 200
  </code></pre>