Link to home
Start Free TrialLog in
Avatar of CSBTech
CSBTech

asked on

Submitting data to web cgi script and parsing results

My company has many products on a popular site.  Not sure I want to give the name here, but may have to eventually.  Anyway, due to technical problems from a third party they use for processing orders many of our products come down from their site because of us being out of stock, even though we aren't.  Long story short, we need to constantly search their site for our products to make sure they are up.  

I am assuming I must use their search somehow.  They use the following cgi script link from a form on their site (url changed to hide site name).

So basically from within access (preferably) or c++ I would like to search for each of our products that are on their site from our products library (in access) and see if they are up on the site.  They use a cgi script to accept data from a form.


Here is the code from their site.

<FORM ACTION="http://www.productsite.com/cgi-bin/d2.cgi" METHOD="GET">  

<TABLE WIDTH="100&#37" BORDER="0" CELLSPACING="0" CELLPADDING="0" ID="searchBar">  
<TR>  
<TD WIDTH="71">
<IMG SRC="http://images.productsite.com/f/102/3117/8h/www.productsite.com/img/mxc/homepage_search_tab1_text.gif" WIDTH="71" HEIGHT="28">
</TD>  
<TD WIDTH="200" CLASS="searchBoxHolder">  
<INPUT NAME="page" TYPE="hidden" VALUE="search">  
<INPUT NAME="keyword" TYPE="text" ID="keyword" onClick=this.value=""; VALUE="Search Keyword or Model #" SIZE="30">
</TD>  

I had only found 1 question dealing with this using xmlhttp but couldn't get it to work with their cgi script because I didn't know how to pass the value.

Thanks in advance.  After I get this working, I will post another question regarding parsing the data.

John
ASKER CERTIFIED SOLUTION
Avatar of mnashadka
mnashadka

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CSBTech
CSBTech

ASKER

I will give that a shot and get back to you.  Thanks.
Avatar of CSBTech

ASKER

Is this code only for visual c++?  I can't find the afxinet.h file and everything I find points to it being a visual c++ file which I don't have.  I am using dev C++.  Is this a library I can download or is this a vc++ file only?

As far as i know, MFC is vc++. I'm not sure if dev c++ has anything for MFC. My suggestion is that you just create your own class for submitting the form data manually.

--trigger-happy
You can use the URLDownloadToFile function in urlmon as well, then read the file within your code.  You could even do this one in Access, like:

Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal _
szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

Private Sub Command0_Click()
  URLDownloadToFile 0, "http://myurl", "c:\local_file.html", 0, 0
End Sub
Avatar of CSBTech

ASKER

The access version worked great and I prefer it in access anyway.  However, I need to parse out the code that is returned (I will handle this in another question shortly if I don't figure it out).  

So my question is, can this be changed to not save the file, but rather assign it to a variable or something else so I can process the file and strip out what I need?
No.  If you want to do that, you'll have to read the data directly off of the socket.  That would be closer to the earlier example.  There's a WinHTTP library that Microsoft has with the platform SDK that you could use in Dev-CPP or Access (with a lot of declare function statements), but it will be much more of a pain.  You could also just create a socket connection to port 80 on the server and send the GET function with the HTTP headers, which would not be a big deal either.  But it's probably a lot easier just to save it and read in the file (which you could do in Access).
Avatar of CSBTech

ASKER

Hmmmm...

Let me explain why I am avoiding the saving thing.

I basically have to check each of our products so see if they are on the site or not.  So I have to perform the function say 200 times, each time getting the results and parsing out if it is out of stock or not from the page, then generating some type of report listing each product and the result of that products search.

So, which would you recommend, what would you suggest, and since I am unfamiliar with this, can you get me started?

I really appreciate the help.

Thanks, John
If you're doing it in Access, the URLDownloadToFile will definitely be your safer bet.  If you'll be calling it from Access, then chances are you'd have to save it to a file so that Access got the data back anyway (unless you're planning on writing an ActiveX control).  It's really up to you.  We might be able to get you started, but ultimately you'll have to finish the thing and maintain it.  If you're not even the least bit comfortable with C++, but you're comfortable with VBA, then I'd go with the URLDownloadToFile.  What do you think?
Avatar of CSBTech

ASKER

Well, I am familiar with C++ by not an expert.  If it is very complex, then you are correct.  As for Access, if there is no other way, then I guess I will have to do the query, save the file, open the file, parse the file, then perform the next query for each product.  Just seems like a lot of processing of opening and closing files.  I guess I will go with the Access and see how it works.  If problems arise in the processing I will revert to another option.