From: Aaron Patterson Date: 2008-08-07T03:31:08+09:00 Subject: Re: help with mechanize Hi Jeremy, On Wed, Aug 06, 2008 at 01:52:57PM +0900, Jeremy Woertink wrote: > I'm using mechanize to log into this form. The redirects aren't going > where I would expect them to though. I don't think i'm being logged in > properly, yet when I try it through the web browser I get logged in > normal. > > I'm looking for maybe a better way on how to do this, or if anyone has > an ideas. I tried out this script, and it looks like Yahoo sends a meta refresh after you log in. Mechanize does not follow meta refreshes by default, so you need to set that option. Change this line: > @agent = WWW::Mechanize.new { |agent| agent.user_agent_alias = 'Windows > Mozilla' } To this: @agent = WWW::Mechanize.new { |agent| agent.user_agent_alias = 'Windows Mozilla' agent.follow_meta_refresh = true } How did I know to do this? I examined the behavior in Firefox and made Mechanize do the same thing. I typically recommend people install LiveHTTPHeaders in firefox and examine the requests and responses. > The only thing I could think of is if the login fails, it returns me > back to a login page. This always says "Not Logged in" even though I > know the @login and @password are correct. Detecting whether or not you are logged in depends on the site you are interacting with. Looking for a 'Not Logged in' string may be appropriate in this case. > On another note, is there any good sites with REALLY good docs on > mechanize, and everything it can do. The main docs page seems to just > show the methods but not really what they do and how to use them. I've tried to document the library as much as possible. "Good docs" is very subjective. I'm doing my best. :-) That said, check EXAMPLES.txt, GUIDE.txt, and also the RDoc for each of the main classes (Mechanize::Page, Mechanize::Form). Hope that helps. -- Aaron Patterson http://tenderlovemaking.com/