# Mechanize

**URL:** <https://www.ruby-forum.com/t/mechanize/170653>\
**Category:** Ruby\
**Created:** [June 20, 2009, 9:09am UTC](https://www.ruby-forum.com/t/mechanize/170653 "2009-06-20T09:09:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![prashantsahni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/977dab/32.png) [@prashantsahni](https://www.ruby-forum.com/u/prashantsahni)\
**Post date:** [June 20, 2009, 9:09am UTC](https://www.ruby-forum.com/t/mechanize/170653/1 "2009-06-20T09:09:46Z")

</div>

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

class NationalGrid

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

login\_page=@agent.get(‘[https://online.nationalgridus.com/eservice\_enu/start.swe?SWECmd=Start](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  
mypage=@agent.get(‘[https://online.nationalgridus.com/eservice\_enu/start.swe?SWECmd=Start](https://online.nationalgridus.com/eservice_enu/start.swe?SWECmd=Start)’)  
#~  
url=‘[https://online.nationalgridus.com/eservice\_enu/start.swe?SWECmd=Start](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  
$newpage=@agent.submit(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
