From: "Иван Бишевац" Date: 2012-11-05T07:17:57+09:00 Subject: Re: login web page using mechanize --047d7b15af19947ae604cdb2bdab Content-Type: text/plain; charset=UTF-8 Your problem is that username and password fields are not inside form. Open Firebug and inspect those fields and you will see that. Instead don't vorry where it is, just select field with name fblogincd and fbpassword, fill in with data, and click on input element with id sImage1. That's all. Is your requirement strictly Mechanize? Mechanize is good for simpler sites without javascript. If you need javascript (you will need it, before or later) then Capybara is better solution. I could write you simple script in Capybara to do this task. 2012/11/4 john smith > 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 > ================================================================= > #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/. > > --047d7b15af19947ae604cdb2bdab Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Your problem is that username and password fields are not inside form.
= Open Firebug and inspect those fields and you will see that.
Inst= ead don't vorry where it is, just select field with name=C2=A0fblogincd and fbpassword, fill in with data, and c= lick on input element with id sImage1. That's all.

Is your requirement strictly Mechanize?=C2=A0Mechanize is good for simple= r sites without javascript. If you need javascript (you will need it, befor= e or later) then Capybara is better solution. I could write you simple scri= pt in Capybara to do this task.


= 2012/11/4 john smith <lists@ruby-forum.com>
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 =3D Mechanize.new
page =3D agent.get('http://www.distance-education.itt-tech.edu/'= )

form =3D page.forms.each do |form|
=C2=A0 pp form
end
=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
=C2=A0{name "loginForm"}
=C2=A0{method "POST"}
=C2=A0{action "javascript:exit('/online/valdoc/cliksIndep_prcsslog= in')"}
=C2=A0{fields
=C2=A0 [hidden:0x1a09478 type: hidden name: fbcorporateid value: 2222]
=C2=A0 [hidden:0x1a093a0 type: hidden name: fbautologin value: 0]
=C2=A0 [hidden:0x1a092d4 type: hidden name: fbloginhome value: ITT]
=C2=A0 [hidden:0x1a09208 type: hidden name: fbGrade value: null]
=C2=A0 [hidden:0x1a0913c type: hidden name: afbTestID value: null]
=C2=A0 [hidden:0x1a09070 type: hidden name: fbPrgLnchId value: null]
=C2=A0 [hidden:0x1a08fa4 type: hidden name: fbuid value: null]}
=C2=A0{radiobuttons}
=C2=A0{checkboxes}
=C2=A0{file_uploads}
=C2=A0{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.

-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/.


--047d7b15af19947ae604cdb2bdab--