httpwebrequest - post form parameters difference between Firefox and Ruby Mechanize -
I'm trying to figure out whether the mechanized correctly post query sends.
I want to log in to a forum (please see my second question) but I only get the login page. I can see that the Firefox parameters like
auth_username = myusername & amp; Auth_password = mypassword & amp; Send a post with auth_login = login
but my script
auth_username = radek & amp; Auth_password = mypassword
This is okay or & amp; Auth_login = Login
should be present in the part?
When I tried to use it using login_form ['auth_login'] = 'login'
I got an error gemstone / mechanization -0.9.3 / Lib / Www>
It seems that auth_login is a form of i button not field (i do not know what it means)
[# & lt; WWW :: mechanism :: form {name}} {method "post"} {action "http: //www.somedomain.com/login?auth_successurl=http://www.somedomain.com/forum/yota?baz_r= 1 "} {Field # & lt; WWW :: Instrumentation :: Form :: field: 0x36 946c0 @name = "Auth_username", @value = "" & gt; # & Lt; WWW :: Instrument :: Form :: field: 0x369451c @ name = "auth_password", @value = "" & gt;} {radiobuttons} {checkbox} {file_uploads} {button # & lt; WWW :: Mechanize :: Form :: Button: 0x36943b4 @ name = "auth_login", @ value = "login" & gt;} & gt; ]
My script is in compliance with
'rubygems' is required' mechanization 'is required' logger agent = WWW :: Mechanize.new {| A | A.log = Logger.new ("loginYOTA.log")} agent.follow_meta_refresh = true #Mechanize does not follow meta refresh by default, we have to set that option. Page = agent.get ("http://www.somedomain.com/login?auth_successurl=http://www.somedomain.com/forum/yota?baz_r=1") login_form = page.form_with (: method = & Gt; 'post') #works says login_form.buttons.inspect page .forms.inspect STDIN.gets login_form.fields.each {| F | "# {F.name}: # {f.value}"} # STDIN.gets login_form ['auth_username'] = 'myusername' login_form ['auth_password'] = 'mypassword' login_form ['auth_login'] = 'Login Is' STDIN.gets page = agent.submit login_form # log in page pagers. Display the message entered in Xpath ("/ html / body / div / div / div / table / tr / td [2] / div / strong"). Xpath ('text ()'). To_s.strip puts puts page.parser.xpath ("/ html / body / div / div / div / table / tr / td [2] / div"). Xpath ('text ()'). To_s.strip output = File.open ("login.html", "w") {| F | | F.write (page.parser.to_html)}
You can login more code, html, and more in my related question
< Div class = "post-text" itemprop = "text">
There was no nerve to log in due to the absence of a parameter in comparison to Firefox in the post. That's why I think the web server needs to be in the and auth_login = login
parameter in POST.
You can read in the second question.
Comments
Post a Comment