eBay Listing Comparison Tool in Visual Basic

Submitted by: 
Language: 
Visitors have accessed this post 129 times.

Introduction:
This tutorial is on how to create a quick and easy eBay listing comparison tool.

Design:
This tool will take two textboxes and a button, one for each eBay listing link and the button to begin the comparison process. The tool will also have two of each following (the naming will be one ending with "1" and the other ending with "2" - for the first and second eBay listing link...)...
title
price
seller
date

Getting The Sources:
Then once the button has been pressed, we want to make sure that the two textbox texts are links to the http www so we ensure they are, then if they are we send a httpwebrequest to the web link, get a response, read the stream to a string variable (src1 or src2, depending on which link we are processing) using a new streamreader's readtoend function to get the entire result and therefore the entire page source...

  1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  2. If (TextBox1.Text.ToLower.StartsWith("http://") And TextBox2.Text.ToLower.StartsWith("http://")) Then
  3. Dim wr As HttpWebRequest = HttpWebRequest.Create(TextBox1.Text)
  4. Dim ws As HttpWebResponse = wr.GetResponse()
  5. Dim src1 As String = New StreamReader(ws.GetResponseStream()).ReadToEnd()
  6. wr = HttpWebRequest.Create(TextBox2.Text)
  7. ws = wr.GetResponse()
  8. Dim src2 As String = New StreamReader(ws.GetResponseStream()).ReadToEnd()
  9. End If
  10. End Sub

Extracting the Information:
Then, lastly, we want to extract the information. For this we are going to create a function named 'getBetween' which will return the entire string from a containing string between two given strings points, make sense?...

  1. Private Function GetBetween(ByVal Source As String, ByVal Str1 As String, ByVal Str2 As String, Optional ByVal Index As Integer = 0) As String
  2. Return Regex.Split(Regex.Split(Source, Str1)(Index + 1), Str2)(0)
  3. End Function

Then we simply go to the source page (in our browser, I'm using Chrome to Inspect the elements) and find a regular expression between the two listing pages. Once you have found one, we can simply use these two points to extract the string of information between them. We do this and set the appropriate labels text for most of the labels...

  1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  2. If (TextBox1.Text.ToLower.StartsWith("http://") And TextBox2.Text.ToLower.StartsWith("http://")) Then
  3. Dim wr As HttpWebRequest = HttpWebRequest.Create(TextBox1.Text)
  4. Dim ws As HttpWebResponse = wr.GetResponse()
  5. Dim src1 As String = New StreamReader(ws.GetResponseStream()).ReadToEnd()
  6. wr = HttpWebRequest.Create(TextBox2.Text)
  7. ws = wr.GetResponse()
  8. Dim src2 As String = New StreamReader(ws.GetResponseStream()).ReadToEnd()
  9. title1.Text = GetBetween(src1, "<span class=""g-hdn"">Details about &nbsp;</span>", "</h1>")
  10. title2.Text = GetBetween(src2, "<span class=""g-hdn"">Details about &nbsp;</span>", "</h1>")
  11. seller1.Text = GetBetween(src1, "<span class=""mbg-nw"">", "</span>")
  12. seller2.Text = GetBetween(src2, "<span class=""mbg-nw"">", "</span>")
  13. price1.Text = "£" + GetBetween(src1, "£", "</span>")
  14. price2.Text = "£" + GetBetween(src2, "£", "</span>")
  15. End If
  16. End Sub

For the estimated delivery date, we need to make the regex area smaller, so we create a string from the page source string, then extract the information from there...

  1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  2. If (TextBox1.Text.ToLower.StartsWith("http://") And TextBox2.Text.ToLower.StartsWith("http://")) Then
  3. Dim wr As HttpWebRequest = HttpWebRequest.Create(TextBox1.Text)
  4. Dim ws As HttpWebResponse = wr.GetResponse()
  5. Dim src1 As String = New StreamReader(ws.GetResponseStream()).ReadToEnd()
  6. wr = HttpWebRequest.Create(TextBox2.Text)
  7. ws = wr.GetResponse()
  8. Dim src2 As String = New StreamReader(ws.GetResponseStream()).ReadToEnd()
  9. title1.Text = GetBetween(src1, "<span class=""g-hdn"">Details about &nbsp;</span>", "</h1>")
  10. title2.Text = GetBetween(src2, "<span class=""g-hdn"">Details about &nbsp;</span>", "</h1>")
  11. seller1.Text = GetBetween(src1, "<span class=""mbg-nw"">", "</span>")
  12. seller2.Text = GetBetween(src2, "<span class=""mbg-nw"">", "</span>")
  13. price1.Text = "£" + GetBetween(src1, "£", "</span>")
  14. price2.Text = "£" + GetBetween(src2, "£", "</span>")
  15. Dim container1 As String = GetBetween(src1, "Estimated by", "</span>")
  16. Dim container2 As String = GetBetween(src2, "Estimated by", "</span>")
  17. date1.Text = GetBetween(container1, "<b>", "</b>")
  18. date2.Text = GetBetween(container2, "<b>", "</b>")
  19. End If
  20. End Sub

As you can see, we get the source from the ebay listing web page between the words "Estimated by" and "" then from that we extract the date in bold between the bold tags ("" and "").

Finished!


Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.