Contents
Instructions
Create an ASP page, inserting the ASP code below at the very
start of the page. You will need to create a database table to hold the
results (see below) and enter a valid connection string in the variable
indicated.
Insert the HTML code below between the <body> tags of
your ASP page. To use the page, enter the row numbers to process and click
submit. The number of pages that you will be able to parse in one run
will vary depending on your script timeout settings and bandwidth.
Use the SQL code to create queries in your database which aggregate
the data you have extracted. Note that a full solution using SQL alone
is not available - you will need to analyze the data in Excel to identify
the correct winning bids because the last bid is not always the winning
bid.
Please note the following:
- No warranties or guarantees are offered for this code. It has been
tested and used by us, but your system settings, eBay changes, and
other factors may stop it working for you.
- You use this code at your own risk. We are not responsible for any
damage or complaint arising from its use.
- You may freely use and adapt this code for any purpose, as you see
fit. Please credit this site if you do so.
ASP Code
<%
Server.ScriptTimeout = 120
Dim strDBConnection, objXMLHttp, strURL, strResponse, Match
Dim Matches, strOutPut, strSQL, con, intRowFrom, intRowTo
Dim intItemIDs(), rstItems, counter, intItemsCount, reBid
Dim reEnded
Const intFirstID = 31
strDBConnection = "ENTER YOUR CONNECTION STRING HERE"
intRowFrom = CLng(Request.Form("rowfrom"))
intRowTo = CLng(Request.Form("rowto"))
If intRowFrom > 0 And intRowTo > 0 Then
ReDim intItemIDs(intRowTo - intRowFrom, 1)
strSQL = "SELECT ItemID, eBayItemID, Bids FROM tblEbayItems" & _
" WHERE ItemID >= " & intRowFrom + intFirstID - 1 & " AND" & _
" ItemID <= " & intRowTo + intFirstID - 1
counter = 0
Set rstItems = Server.CreateObject("ADODB.Recordset")
rstItems.Open strSQL, strDBConnection, 0, 1
Do Until rstItems.EOF
If rstItems.Fields("Bids") > 0 Then
intItemIDs(counter, 0) = rstItems.Fields("ItemID")
intItemIDs(counter, 1) = rstItems.Fields("ebayItemID")
counter = counter + 1
End If
rstItems.MoveNext
Loop
intItemsCount = counter - 1
rstItems.Close()
Set rstItems = Nothing
Set con = Server.CreateObject("ADODB.Connection")
con.Open strDBConnection
Set reBid = New RegExp
reBid.Global = True
reBid.IgnoreCase = True
reBid.Pattern = "<td[^>]*>.*Display bid[^\$]*\$([\d\.\,]*)." & _
"*\n.*time of bid[^>]*>([\w\d\-: ]{18}) PST"
Set reEnded = New RegExp
reEnded.Global = True
reEnded.IgnoreCase = True
reEnded.Pattern = "<font size=""2"">.*\nEnds.*\n<\/font>.*\" & _
"n<\/td>.*\n<td colspan=""4"">([\w\d\-: ]{18}) PST"
For counter = 0 To intItemsCount
strURL = "http://offer.ebay.com/ws3/eBayISAPI.dll?ViewBid" & _
"s&item=" & intItemIDs(counter, 1)
Set objXMLHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.4.0")
objXMLHttp.Open "GET", strURL, False
objXMLHttp.Send
strResponse = objXMLHttp.ResponseText
Set objXMLHttp = Nothing
Set Matches = reEnded.Execute(strResponse)
For Each Match in Matches
strOutput = strOutPut & "<tr><td colspan='2'>ItemID: " & _
intItemIDs(counter, 0) & ", eBayID: " & _
intItemIDs(counter, 1) & " - ENDED: " & _
reEnded.Replace(Match.Value, "$1") & "</td></tr>" & _
vbNewLine
strSQL = "UPDATE tblEbayItems SET DateTimeEnded = '" & _
FormatDateTime(reEnded.Replace(Match.Value, "$1"),1) & _
" " & _
FormatDateTime(reEnded.Replace(Match.Value, "$1"),3) & _
"' FROM tblEbayItems WHERE ItemID = " & _
intItemIDs(counter, 0)
con.Execute strSQL
Next
Set Matches = reBid.Execute(strResponse)
For Each Match in Matches
strOutput = strOutPut & reBid.Replace(Match.Value, "<tr>" & _
" <td>AMOUNT: $1</td> <td>DATETIME: $2</td> </tr>" & _
vbNewLine)
strSQL = reBid.Replace(Match.Value, "INSERT INTO " & _
"tblEbayBids (ItemID, BidAmount, BidTime) VALUES (" & _
intItemIDs(counter, 0) & ",CAST ('$1' AS MONEY),'" & _
FormatDateTime(reBid.Replace(Match.Value, "$2"),1) & " " & _
FormatDateTime(reBid.Replace(Match.Value, "$2"),3) & "')")
con.Execute strSQL
Next
Next
con.Close
Set con = Nothing
strOutput = "<tr><td colspan='2'>Rows " & intRowFrom & " to " & _
intRowTo & " complete</td></tr>" & strOutput
intItemsCount = intRowTo - intRowFrom
intRowFrom = intRowTo + 1
intRowTo = intRowTo + intItemsCount + 1
Else:
intRowFrom = 1
intRowTo = 25
End If
%>
HTML Code
<form name="form" method="post" action=""> From:
<input name="rowfrom" type="text" value="<%=intRowFrom%>"
size="5" maxlength="5"> <br> To:
<input name="rowto" type="text" value="<%=intRowTo%>"
size="5" maxlength="5"> <br> <br> <input name="submit" type="submit" value="Submit"> </form> <br> <table><%=strOutPut%></table> <br>
SQL Code
This finds the last bid placed on each auction (remember that
this is not always the winning bid), call it "qryLastBidTimes":
SELECT ItemID, MAX(BidTime) AS LastBidTime FROM tblEbayBids GROUP BY ItemID
This uses the previous query and tblEbayItems to calculate the
difference in seconds between the last bid placed and the auction end
time:
SELECT tblEbayItems.ItemID,
DATEDIFF(s, qryLastBidTimes.LastBidTime, tblEbayItems.DateTimeEnded)
AS LastBidGap FROM tblEbayItems INNER JOIN qryLastBidTimes ON tblEbayItems.ItemID = qryLastBidTimes.ItemID WHERE
DATEDIFF(s, qryLastBidTimes.LastBidTime, tblEbayItems.DateTimeEnded)
<= 60) ORDER BY
DATEDIFF(s, qryLastBidTimes.LastBidTime, tblEbayItems.DateTimeEnded)
|