I'm trying to connect automaticaly to a website using Mechanize.
I read searched the internet but I can't find any solution to my problem,
which is why when i write nothing in, value = "", I get *Incorrect Login or
Password * but when i write my password i get nothing ?
agent = Mechanize.new{ |a| a.log = Logger.new("mech.log") }
@agent.user_agent_alias = 'Linux Firefox'
login_page = agent.get('http://xxxx.org/?op=my_files ')
login_form = login_page.forms.first
login_field = login_form.field_with(*name: "login"*).value = "MyLogin"
password_field = login_form.field_with(*name: "password"*).value =
"MyPassword"
home_page = login_form.submit
puts home_page.content
the code HTML
<div id="signincontainer">
<form method="POST" action="http://xxx.org/ " name="FL" id="signin">
<input name="op" value="login" type="hidden">
<input name="redirect" value="" type="hidden">
<span class="signinq">
<input style="background: url('images/username.png') no-repeat
scroll 5px 50% rgb(255, 255, 255);" id="username" *name="login"*
title="username" tabindex="4" type="text">
<a class="donthaveaccount" href="http://xxxx.org/signup.html
"><span>
Sign Up
</span></a> </span> <span class="signinq">
<input style="background: url('images/password.png') no-repeat
scroll 5px 50% rgb(255, 255, 255);" id="password" *name="password*"
value="" title="password" tabindex="5" type="password">
<a class="forgotpassword" href="http://xxxx.org/forgot-pass.html "
id="resend_password_link"><span>
Forgot your password?
</span></a> </span>
<input id="signin_submit" value="Enviar" tabindex="6"
src="images2/signin.png" type="image">
</form>
</div>
the log file of the connection :
mechanize.log
[2014-10-18T03:55:01.938082 #16718] INFO -- : Net::HTTP::Get: /?op=my_files
D, [2014-10-18T03:55:01.938162 #16718] DEBUG -- : request-header: accept => */*
D, [2014-10-18T03:55:01.938188 #16718] DEBUG -- : request-header: user-agent => Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624
D, [2014-10-18T03:55:01.938209 #16718] DEBUG -- : request-header: accept-encoding => gzip,deflate,identity
D, [2014-10-18T03:55:01.938230 #16718] DEBUG -- : request-header: accept-charset => ISO-8859-1,utf-8;q=0.7,*;q=0.7
D, [2014-10-18T03:55:01.938250 #16718] DEBUG -- : request-header: accept-language => en-us,en;q=0.5
D, [2014-10-18T03:55:01.938270 #16718] DEBUG -- : request-header: host => xxxx.org
I, [2014-10-18T03:55:02.179135 #16718] INFO -- : status: Net::HTTPOK 1.1 200 OK
D, [2014-10-18T03:55:02.179229 #16718] DEBUG -- : response-header: server => nginx/1.6.0
D, [2014-10-18T03:55:02.179263 #16718] DEBUG -- : response-header: date => Sat, 18 Oct 2014 01:55:02 GMT
This file has been truncated. show original
···
--
I'm trying to connect automaticaly to a website using Mechanize.
I read searched the internet but I can't find any solution to my problem,
which is why when i write nothing in, value = "", I get *Incorrect Login
or Password * but when i write my password i get nothing ?
I can't say for sure what's going on here.
I do notice this:
agent = Mechanize.new{ |a| a.log = Logger.new("mech.log") }
@agent.user_agent_alias = 'Linux Firefox'
Is agent an attr_accessor or something? You've used a bare word 'agent'
above and below, but set the user agent alias on an instance variable
'@agent '.
login_page = agent.get('http://xxxx.org/?op=my_files'\ )
login_form = login_page.forms.first
login_field = login_form.field_with(*name: "login"*).value = "MyLogin"
password_field = login_form.field_with(*name: "password"*).value =
"MyPassword"
home_page = login_form.submit
puts home_page.content
Maybe check agent.current_page at this point, as well? It *should* be the
same as home_page, but...
the code HTML
<div id="signincontainer">
<form method="POST" action="XXX Sex - Free Porn Videos at XXX.com ; name="FL"
id="signin">
<input name="op" value="login" type="hidden">
<input name="redirect" value="" type="hidden">
<span class="signinq">
<input style="background: url('images/username.png') no-repeat
scroll 5px 50% rgb(255, 255, 255);" id="username" *name="login"*
title="username" tabindex="4" type="text">
<a class="donthaveaccount" href="http://xxxx.org/signup.html
"><span>
Sign Up
</span></a> </span> <span class="signinq">
<input style="background: url('images/password.png') no-repeat
scroll 5px 50% rgb(255, 255, 255);" id="password" *name="password*"
value="" title="password" tabindex="5" type="password">
<a class="forgotpassword" href="http://xxxx.org/forgot-pass.html" ;
id="resend_password_link"><span>
Forgot your password?
</span></a> </span>
<input id="signin_submit" value="Enviar" tabindex="6"
src="images2/signin.png" type="image">
</form>
</div>
the log file of the connection :
mechanize.log · GitHub
From the log, it certainly looks like it succeeded.
I have a similar sort of thing in one of my scrapers at:
attr_accessor :user, :pw, :delay_time, :destination, :dry_run
def initialize(options={})
netrc_reader = ::Scrapers::NetrcReader.new(NETRC_MANNING_ENTRY)
@user = options.fetch("user", netrc_reader.user)
@pw = options.fetch("pw", netrc_reader.pw)
@delay_time = options.fetch("delay", DELAY_TIME)
@destination = options.fetch("destination", ".")
@dry_run = options.fetch("dry_run", false)
end
···
On Fri, Oct 17, 2014 at 9:02 PM, Olivier Morel <oliviermo75@gmail.com> wrote:
How can i check i'm logged on the web site ?
Because if i write anything in my variable login i get this in the log
*LOG:*
D, [2014-10-20T16:35:22.507210 #8913 ] DEBUG -- : request-header:
content-length => 52
I, [2014-10-20T16:35:24.660472 #8913 ] INFO -- : status:* Net::HTTPOK 1.1
200 OK*
D, [2014-10-20T16:35:24.660576 #8913 ] DEBUG -- : response-header: server =>
nginx/1.6.0
D, [2014-10-20T16:35:24.660617 #8913 ] DEBUG -- : response-header: date =>
Mon, 20 Oct 2014 14:35:24 GMT
D, [2014-10-20T16:35:24.660653 #8913 ] DEBUG -- : response-header:
content-type => text/html; charset=UTF-8
D, [2014-10-20T16:35:24.660688 #8913 ] DEBUG -- : response-header:
transfer-encoding => chunked
D, [2014-10-20T16:35:24.660722 #8913 ] DEBUG -- : response-header:
connection => keep-alive
*CODE:*
*mechanize = Mechanize.new{ |a| a.log = Logger.new("mech.log") }
mechanize.user_agent_alias = "Linux Firefox" login_page =
mechanize.get('http://xxxxxx.org/?op=my_files
<http://xxxxxx.org/?op=my_files>'\ ) current_page = login_page.forms.first
login_field = current_page.field_with(name: "login").value ="XXXX"
login_field = current_page.field_with(name: "password").value =
"XXXXX@1064" home_page = current_page.submit*
···
2014-10-18 9:25 GMT+02:00 tamouse pontiki <tamouse.lists@gmail.com>:
On Fri, Oct 17, 2014 at 9:02 PM, Olivier Morel <oliviermo75@gmail.com> > wrote:
I'm trying to connect automaticaly to a website using Mechanize.
I read searched the internet but I can't find any solution to my problem,
which is why when i write nothing in, value = "", I get *Incorrect Login
or Password * but when i write my password i get nothing ?
I can't say for sure what's going on here.
I do notice this:
agent = Mechanize.new{ |a| a.log = Logger.new("mech.log") }
@agent.user_agent_alias = 'Linux Firefox'
Is agent an attr_accessor or something? You've used a bare word 'agent'
above and below, but set the user agent alias on an instance variable
'@agent '.
login_page = agent.get('http://xxxx.org/?op=my_files'\ )
login_form = login_page.forms.first
login_field = login_form.field_with(*name: "login"*).value = "MyLogin"
password_field = login_form.field_with(*name: "password"*).value =
"MyPassword"
home_page = login_form.submit
puts home_page.content
Maybe check agent.current_page at this point, as well? It *should* be the
same as home_page, but...
the code HTML
<div id="signincontainer">
<form method="POST" action="XXX Sex - Free Porn Videos at XXX.com ; name="FL"
id="signin">
<input name="op" value="login" type="hidden">
<input name="redirect" value="" type="hidden">
<span class="signinq">
<input style="background: url('images/username.png') no-repeat
scroll 5px 50% rgb(255, 255, 255);" id="username" *name="login"*
title="username" tabindex="4" type="text">
<a class="donthaveaccount" href="http://xxxx.org/signup.html
"><span>
Sign Up
</span></a> </span> <span class="signinq">
<input style="background: url('images/password.png') no-repeat
scroll 5px 50% rgb(255, 255, 255);" id="password" *name="password*"
value="" title="password" tabindex="5" type="password">
<a class="forgotpassword" href="
http://xxxx.org/forgot-pass.html" ; id="resend_password_link"><span>
Forgot your password?
</span></a> </span>
<input id="signin_submit" value="Enviar" tabindex="6"
src="images2/signin.png" type="image">
</form>
</div>
the log file of the connection :
mechanize.log · GitHub
From the log, it certainly looks like it succeeded.
I have a similar sort of thing in one of my scrapers at:
scrapers/lib/scrapers/manning_books.rb at master · tamouse/scrapers · GitHub
--
Cordialement
Olivier Morel