×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Automated login using commandling in ubunto

Automated login using commandling in ubunto

Automated login using commandling in ubunto

(OP)
Hi

I would like to use an script to automaticly login to a webpage, and retrive the webpage to a txt file.

I tryed to get it to work using curl

CODE

curl --user name:password http://www.url.com -v >> webpage.log 

But this does not work, the page is buield in asp and has a form with the login and Password.

I have been trying to read about how to save a login and password, maybi just the cookie, but haven't found anything that helps yet.

Regards
Lhg

RE: Automated login using commandling in ubunto

Hi

Your code will work if the site uses HTTP authentication. If the username and password has to be entered in a HTML form, most probably there is no HTTP authentication behind it. ( No idea whether is possible in ASP. )

Probably you will have to make two requests with curl : first to send the form data for authentication, then to download the page. And most important, you have to make sure the 2nd requests sends back the cookies received on the 1st request.

By the way, I used to do such things with twill. Take a look, is not too complicated.

Feherke.
feherke.ga

RE: Automated login using commandling in ubunto

(OP)
Hi

I just curl the page and this seems to be the password box.

CODE

<div style="width: 180px; margin: 3px 3px 7px 3px;"><table cellspacing="0" cellpadding="0" style="width: 100%;"><tr class="mtop"><td><div style="margin: 10px 3px 0px 10px;"><span class="
TitleHaed">Login <img src="/App_Themes/Normal/Images/Window/Elements/rightarrow.gif"><img src="/App_Themes/Normal/Images/Window/Elements/rightarrow.gif"><img src="/App_Themes/Normal/Images/Windo
w/Elements/rightarrow.gif"></div></td></tr><tr class="mmid"><td><div style="margin: 3px 10px 0px 10px">
<TABLE cellSpacing=3 cellPadding=3 width="100%" border=0>
  <TR vAlign="top">
    <TD align="center" width="55">
            <div style="float: left; margin:5px"><img id="ctl00_mnuLeft1_mSignin_mnuSignin_Image1" src="App_Themes/Normal/Images/Window/Pictures/woman.gif" border="0" /></div>
            <img id="ctl00_mnuLeft1_mSignin_mnuSignin_imgBlank1" src="Images/blank.gif" height="3" width="100%" border="0" />
            <A href="/forgotpassword.aspx">Glemt dit kodeord?</A> </TD>
    <TD>
        <SPAN class="MenuText">Brugernavn</SPAN>  <br />
        <input name="ctl00$mnuLeft1$mSignin$mnuSignin$Username" type="text" maxlength="30" id="ctl00_mnuLeft1_mSignin_mnuSignin_Username" class="Text" onkeypress="return clickButton(event,'ctl00
_mnuLeft1_mSignin_mnuSignin_loginButton')" /><BR>
        <SPAN class="MenuText">Kodeord  <br />
        </SPAN>
        <input name="ctl00$mnuLeft1$mSignin$mnuSignin$Password" type="password" maxlength="30" id="ctl00_mnuLeft1_mSignin_mnuSignin_Password" class="Text" name="password" onkeypress="return clic
kButton(event,'ctl00_mnuLeft1_mSignin_mnuSignin_loginButton')" /><BR>
        <span class="MenuText"><input id="ctl00_mnuLeft1_mSignin_mnuSignin_Remember" type="checkbox" name="ctl00$mnuLeft1$mSignin$mnuSignin$Remember" checked="checked" /><label for="ctl00_mnuLef
t1_mSignin_mnuSignin_Remember">Husk mig</label></span><BR>
         <img id="ctl00_mnuLeft1_mSignin_mnuSignin_imgBlank2" src="Images/blank.gif" height="3" width="100%" border="0" />
        <input type="image" name="ctl00$mnuLeft1$mSignin$mnuSignin$loginButton" id="ctl00_mnuLeft1_mSignin_mnuSignin_loginButton" src="App_Themes/Normal/Images/Buttons/login.gif" onclick="javasc
ript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$mnuLeft1$mSignin$mnuSignin$loginButton", "", true, "signin", "", false, false))" bor
der="0" />
     </TD>
  </TR>
</TABLE>

     </TD>
  </TR> 


twill seems like a good idea, I have a littel problem transfering the eksampel to my retrived code.

CODE -->

setlocal username <your username>
setlocal password <your password>

go http://www.slashdot.org/
formvalue 1 unickname $username
formvalue 1 upasswd $password
submit

code 200     # make sure form submission is correct! 


do I use the ID for the formvalue
id="ctl00_mnuLeft1_mSignin_mnuSignin_Username"
id="ctl00_mnuLeft1_mSignin_mnuSignin_Password"

Regards
Lhg

RE: Automated login using commandling in ubunto

Hi

Well, I always used names in twill commands. Fortunately those inputs have name attributes, so use those. Something like this :

CODE --> twill

formvalue 1 "ctl00$mnuLeft1$mSignin$mnuSignin$Username" your_username_here
formvalue 1 "ctl00$mnuLeft1$mSignin$mnuSignin$Password" your_password_here
submit 

Of course, this will not work if :
  • There are other forms in the page before this one ( for example a search form in the page header, like we have here on Tek-Tips too ). Then you will have to adjust those 1 to match the login form's order number.
  • The form tag's action attribute is empty or has a dummy value. Then you have to find out where the form is actually sent and tell it to twill with formaction 1 real_url_here before calling submit.

Feherke.
feherke.ga

RE: Automated login using commandling in ubunto

(OP)
I'm having trouble getting this to work.

I tryed to change the formvalue but still I only get this message in twill-sh

Quote:


Oops! Twill assertion error on line 1 of 'kandu.twill' while executing

>> formvalue 1 "ctl00$mnuLeft1$mSignin$mnuSignin$Username" l1977

no matching forms!

** UNHANDLED EXCEPTION: no matching forms!

this is the page I am trying to create a autologin script for.
kandu.dk

I'm not sure what you ment by the secound "will not work if"

Thanks
Lhg

RE: Automated login using commandling in ubunto

Hi

Seems they have a "clever" firewall. By default twill sends no User-Agent HTTP request header and that triggers the firewall's suspicion. So it sends back an error page with no form. Probably that is why you get that strange error message.

Add this somewhere before the go command in your twill script :

CODE --> twill

agent "Mozilla/5.0 (Windows NT 6.1; rv:26.0) Gecko/20100101 Firefox/26.0" 

Feherke.
feherke.ga

RE: Automated login using commandling in ubunto

(OP)
Hi

Thanks, it allowed a bit more progress

I changed the login names to

CODE -->

formvalue 1 "ctl00_mnuLeft1_mSignin_mnuSignin_Username" L1977
formvalue 1 "ctl00_mnuLeft1_mSignin_mnuSignin_Password" larshg 

But it is still not working, even thou I am not getting an error anymore

Quote:


twill-sh kandu.twill3
>> EXECUTING FILE kandu.twill3
AT LINE: kandu.twill3:0
AT LINE: kandu.twill3:2
==> at http://kandu.dk/
AT LINE: kandu.twill3:3
AT LINE: kandu.twill3:4
AT LINE: kandu.twill3:5
Note: submit is using submit button: name="ctl00$mnuLeft1$mSignin$mnuSignin$loginButton", value=""

AT LINE: kandu.twill3:7
--
1 of 1 files SUCCEEDED.

Any idears?

Thanks
Lhg

RE: Automated login using commandling in ubunto

Hi

Ouch. There is a syntax error in the page's code : the password input has two name attributes. The browsers use and the server expects the 1st one, but the twill version I use handles the 2nd one.

However is strange that your twill not yelled for that. Maybe your version is better than mine, so try to continue.

Add this after the submit command :

CODE --> twill

code 200
save_html output_file_name.html 

Then run the script and check the resulted output file.

Feherke.
feherke.ga

RE: Automated login using commandling in ubunto

(OP)
Hi

I installed twill on an ubunto linux like this.

CODE

sudo apt-get install python-twill

In the HTML file I can se that the username is added, I cant se the code, I'm not sure if that is if its hidden, or if it didn't work.
And I seem not to have made the Login button

This is an image of the html page.



My current script

CODE

agent "Mozilla/5.0 (Windows NT 6.1; rv:26.0) Gecko/20100101 Firefox/26.0"

go http://kandu.dk/
formvalue 1 "ctl00_mnuLeft1_mSignin_mnuSignin_Username" L1977
formvalue 1 "ctl00_mnuLeft1_mSignin_mnuSignin_Password" larshg
submit

code 200     # make sure form submission is correct

save_html kandu3.html

I can't really figure out how to activate the login
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close