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

Posted on 2007-11-30
Medium Priority
Last Modified: 2013-11-25
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

Question by:tjeffryes
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
LVL 63

Accepted Solution

Zvonko earned 2000 total points
ID: 20389876
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


Author Comment

ID: 20390028
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.

LVL 63

Expert Comment

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 63

Expert Comment

ID: 20390695
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.

LVL 63

Expert Comment

ID: 20390699
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.

Author Comment

ID: 20391454

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

Author Comment

ID: 20391749

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.


Expert Comment

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

Experts Exchange Moderator
LVL 63

Expert Comment

ID: 20394146
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+ ;-)
LVL 63

Expert Comment

ID: 20394158
One more thing: the session and session ID is needed on usbaloon to maintain your ShoppingCart

Author Comment

ID: 20396931
Thanks very much for your hellp.  I have put in a request to change your grade to an A.  

Author Comment

ID: 20396972

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


Author Closing Comment

ID: 31412017
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.

LVL 63

Expert Comment

ID: 20399085
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?


Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question