• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1532
  • Last Modified:

How to retrieve data from online form using winhttp when the onaction of the form is javascript?

I am attempting to use VB with a WinHTTP object to pull data from the following page:


When you do tihs manually, searching for "star", the resulting URL is


However, using WinHTTP and the GET command only returns the intial search page.  If i immediately turn around and try to navigate to the same URL, I do get the contents of the search page, but it retrieves all 8,000 or so items.  It appears as though the "star" parameter is not being passed properly.

I have written several different versions of this code using both the GET command and the POST command, all with the same results.  I have tried adding

     m_objWinHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
     m_objWinHTTP.Send "PageNumber=1&Search=star"

When using POST to no avail.

there appears to be 2 things operating here:

#1:  Perhaps some kind of authentication is going on, which is why you have to attempt twice to get to the page.

#2:  The OnClick() event of the search form is not a URL directly, but instead calls a Javascript function which in turns sets the Action of the form to the full URL with the query parameters at the end.

Any help would be appreciated.


Function BalloonSearch_EXP()
   Const BALLOON_SITE As String = "http://www.usballoon.net/webstore/Search_Result.asp?PageNumber=1&Search=STAR"
        Const HTTP_MAX_TIMEOUT As Long = 10000
        Dim m_objWinHTTP As WinHttp.WinHttpRequest
        Dim strContent As String
        Dim strHTMLBody As String
10      On Error Resume Next
20      Set m_objWinHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
30      If Err Then
40          Err.Clear
50          Set m_objWinHTTP = CreateObject("WinHttp.WinHttpRequest.5")
60          If Err Then
70             Err.Clear
80             GoTo ErrorTrap
90          End If
100     End If
110   On Error GoTo ErrorTrap
      '*  Convert the values
120     m_objWinHTTP.SetTimeouts 75000, HTTP_MAX_TIMEOUT * 1000, 10000, 10000
130     m_objWinHTTP.Open "GET", BALLOON_SITE, False
140     m_objWinHTTP.Send
150     m_objWinHTTP.WaitForResponse 20000
160     strContent = m_objWinHTTP.ResponseText
170      MsgBox InStr(1, strContent, "star", vbTextCompare)
180      MsgBox "Status: " & m_objWinHTTP.StatusText
190      Debug.Print strContent
   '* Second time
200     m_objWinHTTP.SetTimeouts 75000, HTTP_MAX_TIMEOUT * 1000, 10000, 10000
210     m_objWinHTTP.Open "GET", BALLOON_SITE, False
220     m_objWinHTTP.Send
230     m_objWinHTTP.WaitForResponse 90000
240     strContent = m_objWinHTTP.ResponseText
250      Debug.Print strContent
260      MsgBox InStr(1, strContent, "star", vbTextCompare)
270      MsgBox "Status: " & m_objWinHTTP.StatusText
290      Exit Function
300       Return
   '* Code here if desired
310      MsgBox Erl & vbCrLf & Err.Description
320      Err.Clear
End Function

Open in new window

  • 7
  • 6
1 Solution
ZvonkoSystems architectCommented:
The search parameter is taken from query_string not the form field.
But your assumption was right: you need something to get the search working! You need the session cookie.

Like this:

m_objWinHTTP.Open "GET", BALLOON_SITE, False
     strContent = m_objWinHTTP.ResponseText
     MsgBox "F: " & mid(strContent, InStr(1, strContent, "products found matching your criteria") - 30, 300 )
     MsgBox "Status1: " & m_objWinHTTP.StatusText

Open in new window

tjeffryesAuthor Commented:
Okay Zvonko:

You truly are a genius and this works great!  Thanks so much.

However, I don't understand.  I guess there's an awful lot about the winHTTP object that I don't fully understand and I've been using it quite a bit these last 2 years.  I'm definitely awarding you all 500 points, but can you clue me in a bit as to how the solution works?  I'm somehwat familiar with what a cookie is, but have NO IDEA what "ASPSESSIONIDQATDDDTB=HOFDMBKCBBINEBGLDJNKMBLD;" is - where on earth did you come up with that?  

More importantly, why is this line of code necessary with this website when I've never needed it before in applications using winHTTP?  Is it because of the Javascript?

Sorry for so many questions.  If you have an online resource to point me to, that would be sufficient - either that or just your own explanation.

Thanks again.  Any further input you can add would be awesome.

ZvonkoSystems architectCommented:
You graded my solution with a grade B!
Please explain why did you grade with a grade B.

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

ZvonkoSystems architectCommented:
Oh, now I see that you stated a comment with your grading. I did not see it before.
OK, but same for you, you did not ask for explanation and I got no chance to explain the solution to you.

ZvonkoSystems architectCommented:
Now what you can do, if you want to change the grading is to ask Community Support to reopen this question. Post a request here: http:/General/newQuestionWizard.jsp

Place also a link to this question or at least the question number in your reopen request.
tjeffryesAuthor Commented:

I posted a question to the Suppport area.  I have copied it below.  I'd be happy to change the grade if you could possibly explain the solution a bit more.  Thanks!!!



I asked a question and it was answered:  http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_22994114.html#a20390689.  
I was thrilled to have a solution, but no explanation was given.  although it was literally only one line of code, I really didn't understand it.  I told the expert that I was going to give him the full 500 points regardless, but that I would appreciate further comment on how the soltuion works.  Before receiving any answer I awarded the 500 points, but I only gave him a "B" because there was no explanation.

If he provides further explanation, I'd like to give him an A.  However, at this point he is grumbling because I gave him a B.  I think was grade was fair, especially since I gave him the full 500 points.

If he should finally provide more information, can I re-assign his grade to an A?

tim Jeffryes
tjeffryesAuthor Commented:

Support has responded and they say I can change the grade.  If you can provde some explanation as to the questions I asked, I will be more than happy to change the grade to an A.  

Sorry for the confusion.

Request posted for grade change with additional explanation: http://www.experts-exchange.com/Q_22996162.html

Experts Exchange Moderator
ZvonkoSystems architectCommented:
OK, the explanation.

First of all, when you are a server side scripting programmer you are happy your dynamic pages are behaving at least as you expect and not hope that there is one general rule how they behave in any circumstance.
The upper usbaloon site expects a session to be created for a browser user. The session key is stored in a cookie. You can observe that even when you enter your URL in a browser address bar. You will see that even you enter the expected URL of the search result page you have to send the request for a second time. But... you cannot observe it without a tool because you cannot execute the script or submit the form without click on that "Submit Search" button.
I can do that because I have a good friend here on EE in JavaScript topic area: devic
He created a wonderful tool to look into a browser page and do scripting in the target server page. Look into his profile to get that tool: PageSpy
When you look into usbaloon page you can see that a cookie is created for the session and you can submit the form by script like this placed in PageSpy last tab labeled Run:
var theForm = document.forms[0];
theForm.action = "Search_Result.asp?PageNumber=1&Search=STAR";

The problem is that you have to use an existing session ID in your cookie. It worked in your test because you used my session ID in the time frame as long as my session with usbaloon lasted.

That was the explanation.

Now you will ask: How to get that ID for my session?
The answer: Open a new Question ;-)

Is that explanation ok for you for an A+ ;-)
ZvonkoSystems architectCommented:
One more thing: the session and session ID is needed on usbaloon to maintain your ShoppingCart
tjeffryesAuthor Commented:
Thanks very much for your hellp.  I have put in a request to change your grade to an A.  
tjeffryesAuthor Commented:

Thanks very much.  I have put in a requst to change your grade from a B to an A.

tjeffryesAuthor Commented:
thanks for all your help.

I'd still like to know how to acquire the session ID because I'm still essentially without a soltution.  However, this has enabled me to progress with my project and I thank you very much.

Basically what I'm trying to do is pull the search results from the balloon site and post them onto another site.  I have no need of the shopping cart, but I would like to be able to get the session ID.

ZvonkoSystems architectCommented:
Can you please open a new question for better readability and for other experts to participate.
In that new question state one single question. The question cannot be to get a working solution. Question is always a request for answer for the topic you do not understand. So state what you have understood so far and what you next question is, but please only one question.

Also keep in mind that EE will not help you to fetch other domains content. I can help you to understand technical stuff like reading and setting cookies, what you do with that knowledge is out of EE scope, you see?

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now