I've been trying but I cant get this to work. I know HTML is new to me but even so!
My first thought was that the site was being clever by checking if the user was using a browser or not. So I added request headers for User-Agent, Referer and Host. This didn't make any difference.
My next thought was that maybe the site needed to have the search input page sent/get/post before I attempt to POST the values for the search results page. So I added lines for this. However all I got was 401s / Access denied.
I have pasted an extract of my code at the bottom of this post.
I think we can rule out two lines of enquiry:
- The variables being sent. I checked these against what the browsers Developer Log and they match exactly (as far as I can make out!)
- The initial login to the site. I am still using the browser automation for this part so I expect that would set any cookies etc. On a related note - the site assigns a GUID/Session key (visible in the URL) for each login. (The key is used in some of the variables sent)
I am not sure what is preventing this from working.
Next idea = Is it possible that the site could be reading a cookie on each search attempt? If possible then How would I use WinHTTP & Developer Log to find the cookie & send it on each search?
RetryLoadRecord:
'trialling new method
Debug.Assert False
'With CreateObject("Winhttp.winhttprequest.5.1")
'(now using reference library)
Set request = New WinHttpRequest
With request
'web page #1 (search input)
.Open "GET", strSend_RequestHeader, False
.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; NP06; rv:11.0) like Gecko"
.setRequestHeader "Host", strHost
.send
If .Status <> 401 Then
'web page #2 (search results)
.Open "POST", strPost_SearchURL, False
.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; NP06; rv:11.0) like Gecko"
'next line shouldnt be required anymore? (ie now that we GET the search input page)
.setRequestHeader "Referer", strSend_RequestHeader
.setRequestHeader "Host", strHost
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.send strSend_RequestBody
Debug.Print .responseText
Else
Debug.Print "failed to gain access to first page"
End If
End With
Debug.Assert False
Set request = Nothing
Bookmarks