Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Logging Into WebPage & Collecting Source From Another

$
0
0

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:

AutoIt         
  1. #include <IE.au3>
  2. #Include <String.au3>
  3. #include <Array.au3>
  4.  
  5. ; login and user status URLs
  6.  
  7. $loginurl = 'http://localhost:8080/TestSite/checkLogin.jsp?uid=bob&pwd=bob'
  8. $processurl = 'http://localhost:8080/TestSite/UserStatuses.jsp'
  9.  
  10. ; Register IE error handler
  11.  
  12. ; Create the webpage and login to test site then close the webpage to create cookie
  13.  
  14. $loginpage = _IECreate($loginurl, 0, 0, 1, 0)
  15. $pageText = _IEBodyReadText($loginpage)
  16.  
  17. $check = StringInStr($pageText, "Internet Explorer cannot display", 1)
  18. $check2 = StringInStr($pageText, "The password you entered is incorrect", 1)
  19.  
  20. IF $check <> 0 Then    ; error checking to tell me if i've hit the page or if cannot access
  21.    ConsoleWrite("Error - Cannot Open Login Page" & @LF)
  22.    _IEQuit($loginpage)
  23.    Exit
  24. ElseIf $check2 <> 0 Then  ; further error checking to tell me if i've managed to get to my page or failing login
  25.    ConsoleWrite("Error - Cannot Login To Test Site" & @LF)
  26.    _IEQuit($loginpage)
  27.    Exit
  28.  
  29. ; Input element commands for login page ;  This is old code i was using to input username/password into fields.
  30.  
  31. ;Local $oForm = _IEFormGetObjByName($oIE, "frmLogin")
  32. ;Local $oText = _IEFormElementGetObjByName($oForm, "uid")
  33. ;_IEFormElementSetValue($oText, "bob")
  34. ;Local $oText = _IEFormElementGetObjByName($oForm, "pwd")
  35. ;_IEFormElementSetValue($oText, "bob")
  36. ;_IEFormSubmit($oForm)
  37. ;Sleep(5000)
  38. ;$processSource = _INetGetSource($processurl, 'True')
  39.  
  40. ; Create webpage navigate to user status and read the source.  Close the page
  41.  
  42. $processpage = _IECreate($processurl, 0, 0, 1, 0)
  43. $processSource = _IEBodyReadHTML($processpage)
  44.  
  45. $check = StringInStr($processSource, "Internet Explorer cannot display", 1)
  46. $check2 = StringInStr($processSource, "The password you entered is incorrect", 1)
  47.  
  48. IF $check <> 0 Then
  49.    ConsoleWrite("Error - Cannot Open Login Page" & @LF)
  50.    _IEQuit($processpage)
  51.    Exit
  52. ElseIf $check2 <> 0 Then
  53.    ConsoleWrite("Error - Cannot Login To test site" & @LF)
  54.    _IEQuit($processpage)
  55.    Exit
  56.  
  57. _IEQuit($loginpage)
  58. _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

 

 


Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>