# How to login in a page whit a ruby program

**URL:** <https://www.ruby-forum.com/t/how-to-login-in-a-page-whit-a-ruby-program/155672>\
**Category:** Ruby\
**Created:** [December 15, 2008, 2:29pm UTC](https://www.ruby-forum.com/t/how-to-login-in-a-page-whit-a-ruby-program/155672 "2008-12-15T14:29:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![exg10](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/87869e/32.png) [@exg10](https://www.ruby-forum.com/u/exg10)\
**Post date:** [December 15, 2008, 2:29pm UTC](https://www.ruby-forum.com/t/how-to-login-in-a-page-whit-a-ruby-program/155672/1 "2008-12-15T14:29:58Z")

</div>

I need to make a program for login and logout in a web site  
([www.zenzuu.com](http://www.zenzuu.com))

---

<div class="post-metadata">

**Author:** ![exg10](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/87869e/32.png) [@exg10](https://www.ruby-forum.com/u/exg10)\
**Post date:** [December 15, 2008, 3:15pm UTC](https://www.ruby-forum.com/t/how-to-login-in-a-page-whit-a-ruby-program/155672/2 "2008-12-15T15:15:54Z")

</div>

On Mon, Dec 15, 2008 at 7:22 AM, Emmanuel Cruz  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> ## I need to make a program for login and logout in a web site ([www.zenzuu.com](http://www.zenzuu.com))
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

One option would be to use Watir: [http://wtr.rubyforge.org/](http://wtr.rubyforge.org/)

That’s a good starting point.

---

<div class="post-metadata">

**Author:** ![exg10](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/87869e/32.png) [@exg10](https://www.ruby-forum.com/u/exg10)\
**Post date:** [December 15, 2008, 3:46pm UTC](https://www.ruby-forum.com/t/how-to-login-in-a-page-whit-a-ruby-program/155672/3 "2008-12-15T15:46:31Z")

</div>

That’s what Mechanize is for.

[http://mechanize.rubyforge.org/mechanize/](http://mechanize.rubyforge.org/mechanize/)

---

<div class="post-metadata">

**Author:** ![exg10](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/87869e/32.png) [@exg10](https://www.ruby-forum.com/u/exg10)\
**Post date:** [December 15, 2008, 6:05pm UTC](https://www.ruby-forum.com/t/how-to-login-in-a-page-whit-a-ruby-program/155672/4 "2008-12-15T18:05:57Z")

</div>

Hi,

or you can use pure net/http from the standard lib. Then you only need  
managing the cookies:

1. load the login page and (if needed) extract the form data
2. create a login post reqeuest and send it, store the cookies (if  
some) and send them back next time
3. now you can open the next pages as if you were logged in

That’s all. Logout is simply open the logout page or send the logut  
post request. Mechanize just helps you storing your cookies.  
You will maybe also need something like nokogiri or hpricot for html  
parsing.

jannschu
