From: Dave Baldwin Date: 2012-11-06T01:04:43+09:00 Subject: Re: login web page using mechanize On 4 Nov 2012, at 19:41, john smith wrote: > new to ruby, love the language. read programmatic programmers guide to > get started and i understand the basics of ruby language. im just > starting to learn gems, ive played with mysql, crypt, and now mechanize. > I have yet to write a successful program with any of the gems but im > hooked on mechanize. ok so here is what im trying to do... > i am a student in itt tech online course. to get credit for attendance i > have to send emails everyday through the webpage. so i thought "yesss!!! > i can write a program using mechanize to do this for me." > First question: is that even possible? > > next i can get to the webpage and can print the forms but dont know how > to fill it out to submit it. here is my code and what i see when > executed: > > #THIS IS MY CODE > require 'rubygems' > require 'mechanize' > > agent = Mechanize.new > page = agent.get('http://www.distance-education.itt-tech.edu/') > > form = page.forms.each do |form| > pp form > end You could try this. I have not tested it as my mechanize is broken at present. agent = Mechanize.new page = agent.get('http://www.distance-education.itt-tech.edu/') form = page.forms.first begin form.fblogincd = user form. fbpassword = password form.submit rescue pp page raise "Not on login page or expected fields not found." end Dave. > ================================================================= > #THIS IS WHAT IS PRINTED OUT > # {name "loginForm"} > {method "POST"} > {action "javascript:exit('/online/valdoc/cliksIndep_prcsslogin')"} > {fields > [hidden:0x1a09478 type: hidden name: fbcorporateid value: 2222] > [hidden:0x1a093a0 type: hidden name: fbautologin value: 0] > [hidden:0x1a092d4 type: hidden name: fbloginhome value: ITT] > [hidden:0x1a09208 type: hidden name: fbGrade value: null] > [hidden:0x1a0913c type: hidden name: afbTestID value: null] > [hidden:0x1a09070 type: hidden name: fbPrgLnchId value: null] > [hidden:0x1a08fa4 type: hidden name: fbuid value: null]} > {radiobuttons} > {checkboxes} > {file_uploads} > {buttons [imagebutton:0x1a08ef0 type: image name: Login value: ]}> > ====================================================================== > -ok so i see the form, but i dont know which one i would put my user > name and password into. > -Also i use firebug to see the names of the text-fields on the actual > web page and their "names" are not in the list of fields that are > printed out. > > -so my next question is how do i fill out the username and password > fields and click the submit button to get to the next page? id like to > figure it out by myself but i have not been having much luck. any help > is appreciated thank you! > > -- > Posted via http://www.ruby-forum.com/. >