# Mechanize login form

**URL:** <https://www.ruby-forum.com/t/mechanize-login-form/190121>\
**Category:** Ruby\
**Created:** [June 16, 2010, 7:18am UTC](https://www.ruby-forum.com/t/mechanize-login-form/190121 "2010-06-16T07:18:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [June 16, 2010, 7:18am UTC](https://www.ruby-forum.com/t/mechanize-login-form/190121/1 "2010-06-16T07:18:01Z")

</div>

i’m gona to simulate login my ubuntu forum,here is my program

require ‘rubygems’  
require ‘mechanize’  
agent = Mechanize.new  
page =  
agent.get(‘[Ubuntu中文论坛 - 用户控制面板 - 登录](http://forum.ubuntu.org.cn/ucp.php?mode=login&sid=d6179312144b3f8cf843d61b0ba409ca)’)  
uform = page.forms[1]  
uform.username = ‘ç½—éžé±¼’  
uform.password = ‘\*\*\*\*\*’  
uform.action = ‘[Ubuntu中文论坛 - 用户控制面板 - 登录](http://forum.ubuntu.org.cn/ucp.php?mode=login)’  
page = agent.submit(uform)  
page.save(‘/home/pt/ubuntu’)

attention: keyword is absolutely right,here is ommitted.  
i found that i haven’t longin when i open the file /home/pt/ubuntu  
with firefox.  
would you mind to tell me what the matter is in my program?

---

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [June 17, 2010, 4:22pm UTC](https://www.ruby-forum.com/t/mechanize-login-form/190121/2 "2010-06-17T16:22:17Z")

</div>

On Wed, Jun 16, 2010 at 12:18 AM, Pen T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> uform.username = ‘ç½—éžé±¼’  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

Mechanize has its own set of cookies. So you could be logged in with  
Mechanize, and not logged in with Firefox. I found a blog where  
tenderlove  
says you can serialize cookies (  
[http://tenderlovemaking.com/2006/06/22/new-stuff-in-ruby-mechanize-050/](http://tenderlovemaking.com/2006/06/22/new-stuff-in-ruby-mechanize-050/)),  
so  
there is probably a way to share them with Fx, but it might take some  
effort  
to find or write, I really don’t know.
