Jump to content


Photo

[How to] Automate a Web-Login (Requires IE)


  • This topic is locked This topic is locked
17 replies to this topic

#1 SKAN

SKAN
  • Administrators
  • 9062 posts

Posted 11 July 2006 - 02:25 PM

How to automate a Web-Login ? (Requires IE)
http://www.autohotke...p?p=67646#67646

I am posting here an experimental script I wrote for automating AHK-Forum Login.
Alter the first three variables correctly to get working results

UserName=ahkuser
PassWord=ahkuser
IExplore=C:\Program Files\Internet Explorer\iexplore.exe
TempFile=%A_Temp%\AHK-F.htm

MemVar=
( Join
<head>`n<title>AHK.Automated.Login.AHK-Forum</title>`n</head>`n<bodyùbgcolor="#E 
5E5E5"ùtext="#000000"ùlink="#006699"ùvlink="#5493B4"ùleftmargin="15"ùtopmargin=" 
5"ùmarginwidth="5"ùmarginheight="5">`n<aùname="top"></a>ù`n<tableùwidth="300"ùce 
llspacing="0"ùcellpadding="0"ùborder="0"ùalign="left">`nø<tr>ù`nö<tdùclass="body 
line"ùheight="134">ù`nô<formùaction="http://www.autohotkey.com/forum/login.php?s 
id="ùmethod="post"ùtarget="_top">`nò<tableùwidth="100`%"ùcellpadding="0"ùcellspa 
cing="0"ùborder="0"ùclass="forumline"ùalign="center">`nñù<tr>ù`nñ÷<tdùclass="row 
1">ù`nñõ<tableùborder="0"ùcellpadding="2"ùcellspacing="2"ùwidth="100`%">`nñó<tr> 
ù`nññ<tdùwidth="70`%">ù`nññø<inputùtype="text"ùclass="post"ùname="username"ùvalu 
e="u.s.e.r.n.a.m.e"ùsize="25"ùmaxlength="40"ù/>`nññ</td>`nñó</tr>`nñó<tr>ù`nññ<t 
dùwidth="70`%">ù`nññø<inputùtype="password"ùvalue="p.a.s.s.w.o.r.d"ùclass="post" 
ùname="password"ùsize="25"ùmaxlength="32"ù/>`nññ</td>`nñó</tr>`nñó<trùalign="cen 
ter">ù`nññ<td>ù`nññø<divùalign="left"><spanùclass="gen">ù`nññö<inputùtype="check 
box"ùcheckedùname="autologin"ù/>`nññö</span>ù`nññö<inputùtype="hidden"ùname="red 
irect"ùvalue=""ù/>`nññö<inputùtype="submit"ùname="login"ùclass="mainoption"ùvalu 
e="Logùin"ù/>`nññø</div>`nññ</td>`nñó</tr>`nñõ</table>`nñ÷</td>`nñù</tr>`nò</tab 
le>`nô</form>`nô<divùalign="center"></div>`nö</td>`nø</tr>`n</table>`n</body>`n< 
/html> 
)

MemVar:=ExpandSpaces(MemVar) ; uncompress the spaces

StringReplace, MemVar, MemVar, u.s.e.r.n.a.m.e, %UserName%
StringReplace, MemVar, MemVar, p.a.s.s.w.o.r.d, %PassWord%

FileErase(TempFile)
FileAppend, % MemVar, %TempFile%
MemVar=
Run, %IExplore% "%TempFile%", , MAX
WinWaitActive, AHK.Automated.Login.AHK-Forum
IEID1:=WinExist("AHK.Automated.Login.AHK-Forum")
ControlSend, Internet Explorer_Server1, {Tab 5}{Enter}, ahk_id %IEID1%
Sleep, 2000
FileErase(TempFile)
Return

ExpandSpaces(MemVar,Asc=240) {
 Loop, 9 
  StringReplace, MemVar, MemVar, % Chr(Asc+A_Index), % Space(10-a_Index), All
Return MemVar
}

Space(Width) { 
 Loop,%Width% 
  Space=% Space Chr(32) 
Return Space 
}

FileErase(FileName) {
;Thanks to PhiLho: http://www.autohotkey.com/forum/viewtopic.php?p=52564#52564
 handle:=DllCall("CreateFile", "Str",FileName, "UInt",0x40000000
               ,"UInt",3 , "UInt",0 , "UInt",5 , "UInt",0 , "UInt",0)   
 DllCall("CloseHandle", "UInt", handle)
 FileRecycle, %FileName%               ; Change this to: FileDelete, %FileName%
 IfLessOrEqual, handle, 0, Return, 0
Return 1
}

Right click & save this file: ahkloginhtml.txt.txt to see the actual HTML
I will post the text compression technique (used for encoding the HTML text) in a seperate topic.
Meanwhile, let me know if someone wants a similar auto-login script for GMail.

Regards, :)




#2 RedCairo

RedCairo
  • Guests

Posted 21 October 2011 - 01:21 PM

Hi there,

I really would like the other script you mentioned, to automate Gmail login. And ideally just something I could customize to work out login on anything (I assume there are tab indexes or mouse click locations or something custom to each).

I am brand new to AHK so still basically an idiot, but the web login and gmail login were early on my list of ideal things to start with. :-)

Thanks!
Palyne

#3 Learning one

Learning one
  • Members
  • 1292 posts

Posted 21 October 2011 - 01:35 PM

Edit by SKAN: Requires AHK_L

I really would like... ...to automate Gmail login.

Welcome to the forum RedCairo. You can use this;
GMailLogIn("[color=red]WriteYourUserNameHere[/color]","[color=red]WriteYourPasswordHere[/color]")

GMailLogIn(UserName,Password) {
	pwb := ComObjCreate( "InternetExplorer.Application") 
	pwb.Visible := True
	pwb.Navigate( "http://mail.google.com/mail")
	While, (pwb.ReadyState <> 4)
	Sleep, 100
	pwb.document.all.Email.value := UserName
	pwb.document.all.Passwd.value := Password
	pwb.document.all.signIn.click	
}


#4 RedCairo

RedCairo
  • Guests

Posted 29 October 2011 - 10:43 AM

Thanks very much!!

#5 azure

azure
  • Members
  • 1203 posts

Posted 27 November 2011 - 06:41 PM

How to automate a Web-Login ? (Requires IE)
http://www.autohotke...p?p=67646#67646

I am posting here an experimental script I wrote for automating AHK-Forum Login.
Alter the first three variables correctly to get working results

UserName=ahkuser
PassWord=ahkuser
IExplore=C:\Program Files\Internet Explorer\iexplore.exe
TempFile=%A_Temp%\AHK-F.htm

MemVar=
( Join
<head>`n<title>AHK.Automated.Login.AHK-Forum</title>`n</head>`n<bodyùbgcolor="#E 
5E5E5"ùtext="#000000"ùlink="#006699"ùvlink="#5493B4"ùleftmargin="15"ùtopmargin=" 
5"ùmarginwidth="5"ùmarginheight="5">`n<aùname="top"></a>ù`n<tableùwidth="300"ùce 
llspacing="0"ùcellpadding="0"ùborder="0"ùalign="left">`nø<tr>ù`nö<tdùclass="body 
line"ùheight="134">ù`nô<formùaction="http://www.autohotkey.com/forum/login.php?s 
id="ùmethod="post"ùtarget="_top">`nò<tableùwidth="100`%"ùcellpadding="0"ùcellspa 
cing="0"ùborder="0"ùclass="forumline"ùalign="center">`nñù<tr>ù`nñ÷<tdùclass="row 
1">ù`nñõ<tableùborder="0"ùcellpadding="2"ùcellspacing="2"ùwidth="100`%">`nñó<tr> 
ù`nññ<tdùwidth="70`%">ù`nññø<inputùtype="text"ùclass="post"ùname="username"ùvalu 
e="u.s.e.r.n.a.m.e"ùsize="25"ùmaxlength="40"ù/>`nññ</td>`nñó</tr>`nñó<tr>ù`nññ<t 
dùwidth="70`%">ù`nññø<inputùtype="password"ùvalue="p.a.s.s.w.o.r.d"ùclass="post" 
ùname="password"ùsize="25"ùmaxlength="32"ù/>`nññ</td>`nñó</tr>`nñó<trùalign="cen 
ter">ù`nññ<td>ù`nññø<divùalign="left"><spanùclass="gen">ù`nññö<inputùtype="check 
box"ùcheckedùname="autologin"ù/>`nññö</span>ù`nññö<inputùtype="hidden"ùname="red 
irect"ùvalue=""ù/>`nññö<inputùtype="submit"ùname="login"ùclass="mainoption"ùvalu 
e="Logùin"ù/>`nññø</div>`nññ</td>`nñó</tr>`nñõ</table>`nñ÷</td>`nñù</tr>`nò</tab 
le>`nô</form>`nô<divùalign="center"></div>`nö</td>`nø</tr>`n</table>`n</body>`n< 
/html> 
)

MemVar:=ExpandSpaces(MemVar) ; uncompress the spaces

StringReplace, MemVar, MemVar, u.s.e.r.n.a.m.e, %UserName%
StringReplace, MemVar, MemVar, p.a.s.s.w.o.r.d, %PassWord%

FileErase(TempFile)
FileAppend, % MemVar, %TempFile%
MemVar=
Run, %IExplore% "%TempFile%", , MAX
WinWaitActive, AHK.Automated.Login.AHK-Forum
IEID1:=WinExist("AHK.Automated.Login.AHK-Forum")
ControlSend, Internet Explorer_Server1, {Tab 5}{Enter}, ahk_id %IEID1%
Sleep, 2000
FileErase(TempFile)
Return

ExpandSpaces(MemVar,Asc=240) {
 Loop, 9 
  StringReplace, MemVar, MemVar, % Chr(Asc+A_Index), % Space(10-a_Index), All
Return MemVar
}

Space(Width) { 
 Loop,%Width% 
  Space=% Space Chr(32) 
Return Space 
}

FileErase(FileName) {
;Thanks to PhiLho: http://www.autohotkey.com/forum/viewtopic.php?p=52564#52564
 handle:=DllCall("CreateFile", "Str",FileName, "UInt",0x40000000
               ,"UInt",3 , "UInt",0 , "UInt",5 , "UInt",0 , "UInt",0)   
 DllCall("CloseHandle", "UInt", handle)
 FileRecycle, %FileName%               ; Change this to: FileDelete, %FileName%
 IfLessOrEqual, handle, 0, Return, 0
Return 1
}

Right click & save this file: ahkloginhtml.txt.txt to see the actual HTML
I will post the text compression technique (used for encoding the HTML text) in a seperate topic.
Meanwhile, let me know if someone wants a similar auto-login script for GMail.

Regards, :)



can this work in Opera and in any website?

#6 SKAN

SKAN
  • Administrators
  • 9062 posts

Posted 27 November 2011 - 07:59 PM

can this work in Opera and in any website?


I have not used Opera.
The HTML template should be different for other sites.
I would not recommend this. COM is best suited for web automation.

#7 gregmartinez

gregmartinez
  • Members
  • 1 posts

Posted 09 June 2012 - 07:50 AM

Hello everyone! I'm newbie here. I really don't understand how this thing works but I really like the idea of automating a web-login.
Can anyone explain how this thing works please. Any help is highly appreciated. Thanks. :)

#8 pro682

pro682
  • Members
  • 4 posts

Posted 21 July 2012 - 10:22 PM

Basically it creates a fake html page with the needed stuff to log in to the forum and it sends the information to the autohotkeys forum. The forum doesn't know the difference because everything it needs to log you in is there.

#9 Iony

Iony
  • Members
  • 6 posts

Posted 05 September 2012 - 01:09 PM

Thanks very much for this tutorial! I try this way end hope to succed!

#10 helpen

helpen
  • Members
  • 2 posts

Posted 09 October 2012 - 11:42 AM

merci!, is very useful :)

#11 Lepertum

Lepertum
  • Members
  • 1 posts

Posted 23 November 2012 - 08:28 PM

I'm quite new to this and I've put in several hours in the past to get something similar for this website from my school where we have to login with our emailadress and pw every singe time as it doesnt save anything. Could anyone help me out here? The website is https://blackboard.a...al/frameset.jsp

#12 faqbot

faqbot
  • Members
  • 644 posts

Posted 23 November 2012 - 11:03 PM

The top post is very old and although it probably still works is is not the best method anymore, the one a few posts down http://www.autohotke...ie/#entry461378 is using the latest ahk (sometimes still referred to as ahk_l) and COM which should work a lot better PROVIDED you use Internet Explorer. COM is only for IE.

Looking at the url your site uses a frameset which makes it a bit harder, you need to download the IWB2 learner http://www.autohotke...r-iwebbrowser2/ to help you figure out what values to use. And then start reading here http://www.autohotke...l-for-webpages/

#13 Blackholyman

Blackholyman
  • Members
  • 1198 posts

Posted 24 November 2012 - 12:21 AM

Heres a video of how you can make a AHk/COM "login script" work for new sites :)



Loginname := "Your Login name here"
Password := "Your Password here"

URL := 

WB := ComObjCreate("InternetExplorer.Application")
WB.Visible := True
WB.Navigate(URL)
While wb.readyState != 4 || wb.document.readyState != "complete" || wb.busy ; wait for the page to load
   Sleep, 10
wb.document.getElementById("login").value := Loginname
wb.document.getElementById("password").value := Password
wb.document.getElementsByTagName("Button")[1].Click()
While wb.readyState != 4 || wb.document.readyState != "complete" || wb.busy ; wait for the page to load
   Sleep, 10
Msgbox, Something like that i hope!
return

Hope it helps

#14 mickeyc

mickeyc
  • Members
  • 1 posts

Posted 27 November 2012 - 09:16 AM

Morning.

I am not able to watch the video whilst at work, but I have searched and searched the web for a solution to a problem I am facing.

Please could somebody knock me up a script to log into the following website (or even just to auto type the name and password, the user could tick the box and accept)

https://online.espresso.co.uk/espresso/login/Authn/UserPassword


This is a for a behavioural school and they cannot type the long-winded username all the time, and it would be timewasting for the teacher to do it multiple times too.

#15 Blackholyman

Blackholyman
  • Members
  • 1198 posts

Posted 27 November 2012 - 10:50 PM


wb.document.all.j_username.value := Loginname
wb.document.all.j_password.value := Password
wb.document.getElementByID("checkbox").checked := True
wb.document.all.loginForm.submit()


Hope it helps