Sign in to follow this  
Followers 0
rc1986

Logging Into WebPage & Collecting Source From Another

1 post in this topic

Hi All,

I am currently trying to find the best way to log into a web page using a username/password to create a cookie.  This will then enable me to access a webpage within that site and obtain the source code from it for my use.

Currently I have used the following:

#include <IE.au3>
#Include <String.au3>
#include <Array.au3>

; login and user status URLs

$loginurl = 'http://localhost:8080/TestSite/checkLogin.jsp?uid=bob&pwd=bob'
$processurl = 'http://localhost:8080/TestSite/UserStatuses.jsp'

; Register IE error handler
_IEErrorHandlerRegister()

; Create the webpage and login to test site then close the webpage to create cookie

$loginpage = _IECreate($loginurl, 0, 0, 1, 0)
$pageText = _IEBodyReadText($loginpage)

$check = StringInStr($pageText, "Internet Explorer cannot display", 1)
$check2 = StringInStr($pageText, "The password you entered is incorrect", 1)

IF $check <> 0 Then    ; error checking to tell me if i've hit the page or if cannot access
   ConsoleWrite("Error - Cannot Open Login Page" & @LF)
   _IEQuit($loginpage)
   Exit
ElseIf $check2 <> 0 Then  ; further error checking to tell me if i've managed to get to my page or failing login
   ConsoleWrite("Error - Cannot Login To Test Site" & @LF)
   _IEQuit($loginpage)
   Exit
EndIf  

; Input element commands for login page ;  This is old code i was using to input username/password into fields.

;Local $oForm = _IEFormGetObjByName($oIE, "frmLogin")
;Local $oText = _IEFormElementGetObjByName($oForm, "uid")
;_IEFormElementSetValue($oText, "bob")
;Local $oText = _IEFormElementGetObjByName($oForm, "pwd")
;_IEFormElementSetValue($oText, "bob")
;_IEFormSubmit($oForm)
;Sleep(5000)
;$processSource = _INetGetSource($processurl, 'True')

; Create webpage navigate to user status and read the source.  Close the page

$processpage = _IECreate($processurl, 0, 0, 1, 0)
$processSource = _IEBodyReadHTML($processpage)

$check = StringInStr($processSource, "Internet Explorer cannot display", 1)
$check2 = StringInStr($processSource, "The password you entered is incorrect", 1)

IF $check <> 0 Then 
   ConsoleWrite("Error - Cannot Open Login Page" & @LF)
   _IEQuit($processpage)
   Exit
ElseIf $check2 <> 0 Then
   ConsoleWrite("Error - Cannot Login To test site" & @LF)
   _IEQuit($processpage)
   Exit
EndIf  

_IEQuit($loginpage)
_IEQuit($processpage)

This I've noticed opens an instance of Internet Explorer to perform the work which obviously can be a bit resource intensive.  

I'd like to find another way of doing this, is there such a way to just send a webpage the revelant url with login details to create a cookie to then allow me to just navigate to collect the source from my users page?  

I've tried to use _INetGetSource($myURL, 'true') to get the source which works fine but of course I cannot use this unless I have a nice way of passing the login details to the first page to give me access to this second page.

Any ideas??

Kind regards,

Rob

 


Thanks

Rob

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0