Mechanize

P

Prashant Sahni

i m working on parsing of site with given url
https://online.nationalgridus.com/eservice_enu/start.swe?SWECmd=Start
i have written following code

class NationalGrid

def self.charge
@agent = WWW::Mechanize.new

[email protected]('https://online.nationalgridus.com/eservice_enu/start.swe?SWECmd=Start')
pp login_page
# pp login_page.fields
# login_page.links.text(/Log In/)

mypage=login_page.forms.name('SWEEntryForm').action('/login/Login') do
|f|
f.uid.value='unitedhousing'
f.response.value='uhmgt1'
@agent.click(login_page.buttons.first)
end.submit

mypage.links.each do |link|
puts link
end

pp mypage
end
end

i m trying to login into the page
but the login field is embedded in the table
and mechanize is unable to show it in the fields,when we print the page
i want to how to access this
Login field...for this this site.....plz i need

i have also written following code but it is also not working

class NationalGrid

def self.charge
@agent = WWW::Mechanize.new
[email protected]('https://online.nationalgridus.com/eservice_enu/start.swe?SWECmd=Start')
#~
url='https://online.nationalgridus.com/eservice_enu/start.swe?SWECmd=Start'
#~ $doc=Hpricot(open(url))
p "praas"


myform=mypage.forms.name("SWEEntryForm")

uid = WWW::Mechanize::Field.new('uid', '')
mypage.forms.first.fields.push(uid)


password=WWW::Mechanize::Field.new('password','')
mypage.forms.first.fields.push(password)




button=WWW::Mechanize::Button.new('Submit','Log In')
#name,value,checked,form name
mypage.forms.first.buttons.push(button)
#@agent.submit(myform,myform.button.first)
pp myform

userid=mypage.forms.first.fields.find{|field| field.name=="uid"}
password=mypage.forms.first.fields.find{|field| field.name=="password"}

userid.value="unitedhousing"
password.value="uhmgt1"

puts "This is My Button"
pp mypage.forms.first.buttons.first
[email protected](mypage.forms.first,mypage.forms.first.buttons.first)
npage=Hpricot($newpage.body)

puts npage #the out put of this is result into login failure
end
end


NationalGrid.charge
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top