Forum: Ruby How to get the cookie from a website?

10957dc0546275790a8bd68d4cb9356a?d=identicon&s=25 song yangyang (songyangyang)
on 2013-04-15 11:53
Recently,I am confused that how to get cookie from a website.I installed
Mechanize,but don't know how to use it.need help.
0dfd10ad198ae5a87640da046a77a90a?d=identicon&s=25 Robert Jackson (Guest)
on 2013-04-15 14:37
(Received via mailing list)
On Apr 15, 2013, at 5:53 AM, song yangyang <lists@ruby-forum.com> wrote:

> I am confused that how to get cookie from a website.

Mechanize does keep track of the cookies that are set during various
requests.

Quick example:

```
require 'mechanize'

agent = Mechanize.new
agent.get 'https://google.com'
p agent.cookies
```

A few resources:

http://mechanize.rubyforge.org/
http://mechanize.rubyforge.org/Mechanize/CookieJar.html
http://mechanize.rubyforge.org/Mechanize/Cookie.html
E088bb5c80fd3c4fd02c2020cdacbaf0?d=identicon&s=25 "Jesús Gabriel y Galán" <jgabrielygalan@gmail.com> (Guest)
on 2013-04-15 14:38
(Received via mailing list)
On Mon, Apr 15, 2013 at 11:53 AM, song yangyang <lists@ruby-forum.com>
wrote:
> Recently,I am confused that how to get cookie from a website.I installed
> Mechanize,but don't know how to use it.need help.

agent = Mechanize.new
page = agent.get("http://www.google.com/")
agent.cookies

Jesus.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.