Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

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


  • This topic is locked This topic is locked
17 replies to this topic
SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

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, :)



kWo4Lk1.png

RedCairo
  • Guests
  • Last active:
  • Joined: --
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

Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009
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	
}


RedCairo
  • Guests
  • Last active:
  • Joined: --
Thanks very much!!

azure
  • Members
  • 1216 posts
  • Last active: Mar 18 2015 09:06 AM
  • Joined: 07 Jun 2007

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?

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

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.

gregmartinez
  • Members
  • 1 posts
  • Last active: May 30 2012 11:06 AM
  • Joined: 30 May 2012
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. :)

pro682
  • Members
  • 4 posts
  • Last active: Dec 09 2010 08:54 PM
  • Joined: 04 Apr 2008
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.

Iony
  • Members
  • 6 posts
  • Last active: Jun 26 2012 08:54 AM
  • Joined: 26 Jun 2012
Thanks very much for this tutorial! I try this way end hope to succed!

helpen
  • Members
  • 2 posts
  • Last active: Oct 09 2012 11:35 AM
  • Joined: 09 Oct 2012
merci!, is very useful :)

Lepertum
  • Members
  • 1 posts
  • Last active: Nov 23 2012 08:31 PM
  • Joined: 23 Nov 2012
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

faqbot
  • Members
  • 997 posts
  • Last active:
  • Joined: 10 Apr 2012
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/

Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
Heres a video of how you can make a AHk/COM "login script" work for new sites :)

http://www.youtube.com/watch?v=0lgTc9hBMs8

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
Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About

mickeyc
  • Members
  • 1 posts
  • Last active: Nov 27 2012 09:24 AM
  • Joined: 27 Nov 2012
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.

Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012

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
Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About