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