On 4 Nov 2012, at 19:41, john smith <lists / ruby-forum.com> 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?
>=20
> 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:
>=20
> #THIS IS MY CODE
> require 'rubygems'
> require 'mechanize'
>=20
> agent =3D Mechanize.new
> page =3D agent.get('http://www.distance-education.itt-tech.edu/')
>=20
> form =3D 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 =3D Mechanize.new
page =3D agent.get('http://www.distance-education.itt-tech.edu/')
form =3D page.forms.first
begin
	form.fblogincd =3D user
	form. fbpassword =3D password
	form.submit
rescue
	pp page
	raise "Not on login page or expected fields not found."=09
end		=09


Dave.



> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> #THIS IS WHAT IS PRINTED OUT
> #<Mechanize::Form
> {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: ]}>
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> -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.
>=20
> -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!
>=20
> --=20
> Posted via http://www.ruby-forum.com/.
>=20