Thursday, September 15, 2005

eBaySearch Technique and cflocation

Goal: Submit eBay search Queries through URL.

Story:
Well, every time, I go to eBay I have good search form there. The search is pretty good but sometime it brings wrong information as user has entered the wrong information in it. Well, I do not have any solution for that. There could be some good information in the book “eBay Hack” but I do not have that book so I have to figure out myself.
At present I am working in the company which has to do search in the http://www.ebaymotors.com/. Well, what we were trying to bring out is the similar car information what user is about to launch the auction.

Problems Faced:
• eBay does not allow you to pass the parameter in the URL and it rewrites the URL if you pass any other value then exact string.
• eBay uses JavaScript rewriting the form and submits to DLL of it which brings back the results.
• eBay does not use common delimiter like ?, =, &, comma or other.
• Post or Get can not be used.
• We wanted to be completely legal and did want to use their API, as eBay does not provide API for search, eBay want the user to come to their site to do the search.
• While using any of the form method it posts like this in the URL like
http://mysearch.cfm/?searchterm=car&cat=hondainstead eBay will use following search URL

http://mysearch?searchcatQQAcarZcatQQAhondamoremoremore


Solution:
Using try and error and different approaches finally I figured out following logic. This is for the information and it is not authorized by eBay or any other API development programs.

This only works with PASSENGER cat in eBayMotors:

BASE URL:

http://motors.search.ebay.com/_W0QQsacategoryZ6001


MAKE Parameter: QQsamotorsmakeZbmw

MODEL Parameter: QQsamotorsmodelZ3Q20Series

START YEAR Parameter: QQsamotorsstartyearZ2000

END YEAR Parameter: QQsamotorsendyearZ2000

ALL ITEMS - Pass no value

AUCTIONS - Pass QQsasaleclassZ1

BUY IT NOW - Pass QQsasaleclassZ2

SEPERATOR (LIKE=) – QQSA

DELIMITER – Z

SPACE BETWEEN WORD – Q20


Architecture:
As we know we can not use get or post as they will post the param in the form of the coldfusion and using = and & in them. What we had to do is that we have to create the required search string first and then after open a new page and display the results there.
I finally decided to use the <cflocation url= “someurl”> tag there as it directs the page to the url specified in the tag.
In summery the architecture development steps are as follows.
• Create a form
• Submit to new page use target=_blank
• Create a search string
• Use cflocation to direct that to ebay search page
• Smile.

Result:
We were finally able to create required search string and accomplish our task..

Code:

Use following function to replace things in variable:
<cfset variables.ebay_make = rereplace("#trim(EbayCat.CatName)#"," ", "Q20", "all")>

=====

Use following code to direct to eBay Page:locationpage.cfm
<cfoutput>
<cflocation url="#display_compare##with_the_compare#">
</cfoutput>

=====

Following is the constructions of the form using drop down menu:
<form name="comparable_auctions" method="post" action="locationpage.cfm" target="_blank">
<strong>Comparable Auctions</strong><br><br>
Display
<select name="display_compare" style="font-size:10px; width: 141px;">
<option value="http://motors.search.ebay.com/_W0QQsacategoryZ6001QQsasaleclassZ1">
Auctions Only</option>
<option value="http://motors.search.ebay.com/_W0QQsacategoryZ6001QQsasaleclassZ2">
Buy It Now Auctions Only</option>
<option value="http://motors.search.ebay.com/_W0QQsacategoryZ6001">
All Listings</option>
</select>
with the
<select name="with_the_compare" style="font-size:10px; width: 161px;">
<option value="<cfoutput>QQsamotorsmakeZ#trim(variables.ebay_make)#
QQsamotorsmodelZ#trim(variables.ebay_model)#</cfoutput>">
Same make and model</option>
<option value="<cfoutput>QQsamotorsmakeZ#trim(variables.ebay_make)#
QQsamotorsmodelZ#trim(variables.ebay_model)#QQsamotorsstartyearZ
#trim(val(variables.year))#QQsamotorsendyearZ#trim(val(variables.year))#</cfoutput>">
Same make, model and year</option>
</select>
<input type="submit" value=" View " >
</form>

Online references:

We do not need as I already have wrote most of it here.

---Pinal