0

With my code (given below), I capture source of my website's webpage and then I am trying to find a string with InStr and process it with Split. Everything is working but I have an issue where I need help.

When I am logged in to my website supplying the username and password, I can see the string in the webpage source but when I am in a logged out state, my string is not visible in the webpage source. What changes do I need in the code which will tell the computer that I am logged in.

Is this a cache/cookies issue? if yes, how to code it so that it honors the browser cache/cookies remembering that the user is logged in and gets the source as it shows up in logged in state?

Appreciate a reply. Thanks

Sub source()
    Dim oHttp As New WinHttp.WinHttpRequest
    Dim sURL As String
    Dim webpageSource As String
    sURL = "http://www.google.com"
    oHttp.Open "GET", sURL, False
    oHttp.send
    webpageSource = oHttp.ResponseText
End Sub
Community
  • 1
  • 1
Sabha
  • 621
  • 10
  • 32
  • Possible answers to such questions depends on the kind of "Login". Simple HTTP-Authentication is possible using `WinHttpRequest`. Logon procedures using a form and server side authentication dependent on the credentials given in that form may need a complete other approach. So without the exact website at issue, no help is possible. – Axel Richter Oct 09 '15 at 06:38
  • Thank you for you reply. I understand it would be difficult for anyone to even come close to a solution if the website is not provided. Unfortunately, my website is not hosted. I need to know if cookies/cache is the issue and if yes, i need to know some syntax to deal with cookies and cache. I hope I have conveyed what exactly I am looking at. However, wish to give an example. You may not see the string "My Account" in the webpage source if the user is NOT logged in but it will be visible if the user is logged in. – Sabha Oct 09 '15 at 06:53
  • I found out.... it may not be logged in logged out or cookies/cache issue. Actually, the responsetext output is incomplete. I have started a new thread here http://stackoverflow.com/questions/33042430/http-response-text-fetching-incomplete-html – Sabha Oct 09 '15 at 15:50
  • I was wrong. It must be an issue with logged in logged out state or cookies/cache. Please help – Sabha Oct 09 '15 at 16:52
  • As I said already, to be able to help one must know what kind of logon process is used there. Can you look into the HTML-source-code whether there is a logon form? Like so: `
    .........
    `? If so please post this HTML into your question.
    – Axel Richter Oct 09 '15 at 17:06
  • Thanks. I just added the html in my question – Sabha Oct 09 '15 at 17:28
  • 1
    do you want to suggest opening ie browser via excel vba and use innerhtml or something to get the data what i want? Also, is it not possible in the present approach to pass cookies manually before the .send command so that it knows that i am logged in? because when i login in the browser, it saves a cookie so that I dont have to login again and again. similarly, can that cookie be used before oHttp.send? – Sabha Oct 09 '15 at 17:58
  • 1
    To your first question: yes. `WinHttp` is a client of its own. So it will have its own cookies. You can't take over sessions from one client to another. At least you should not can ;-). So you will at least one time must login with `WinHttpRequest`. And since the login form seems depending of JavaScript and `WinHttpRequest` does not support JavaScript ... – Axel Richter Oct 09 '15 at 18:12
  • Thank you so very much for your kind assistance. God bless – Sabha Oct 09 '15 at 18:26

0 Answers0