Get the selling price of an eBay Item

This function gives the programmer the ability to get the selling price of any eBay item. It works on international eBay versions and uses the WebRequest object to get the information from the website. It is a rather slow process, it needs to get the information from the website and then loop through all the HTML until it finds the right value, but it is quite useful for eBay developers.

VB.NET

''' <summary>
''' Gets the price of the ebay item getting sold.
''' </summary>
''' <param name="URL">The URL to get the price from.</param>
''' <returns>A String Result of the cost of the item.</returns>
''' <remarks></remarks>

Public Function getEbayPrice(ByRef URL As String) As String
    ' Declare the variables
    Dim wrq As Net.WebRequest = Net.WebRequest.Create(URL)
    Dim wrp As Net.WebResponse = wrq.GetResponse()
    Dim sr As IO.StreamReader = New IO.StreamReader(wrp.GetResponseStream())

    Dim Line As String = sr.ReadLine()

    ' Loop through and find the HTML line with the value we need.
    ' When we find it, we will remove the text we don't need, resulting
    ' in the selling price.
    Do Until Line Is Nothing
        If Line.Contains("DetailsCurrentBidValue") Then
            Line = Line.Remove(0, InStr(Line, "DetailsCurrentBidValue") + 47)
            Line = Line.Remove(InStr(Line, "<") - 2)
            sr.Close()
            wrp.Close()
            Return Line
        End If
        Line = sr.ReadLine
    Loop

    ' Clean Up.

    sr.Close()
    wrp.Close()

    ' Return False because we didn't find the value.
    Return False
End Function

' Example usage of the function.
MessageBox.Show(getEbayPrice("http://cgi.ebay.com/Cute-BFF-LOL-BRB-Chat-Texting-Hot-Topic-Emo-T-Shirt-Tee_W0QQitemZ120192899461QQihZ002QQcategoryZ63869QQssPageNameZWDVWQQrdZ1QQcmdZViewItem"))

See Also

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License