How to Create an eBay Listing Information Grabber in Visual Basic

Introduction: Welcome to my tutorial on how to create an eBay Listing Information Grabber in Visual Basic. Steps of Creation: Step 1: First we want to add some imports;
  1. Imports System.Text.RegularExpressions
  2. Imports System.Net
  3. Imports System.IO
We also want to make a form with; textbox1 - contain the eBay Listing Link, button1 - to begin the information grabbing process. Step 2: Next we want to create a custom function which will return a string between two points of strings within a larger string...
  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
Step 3: Now, on button1 click action event, we want to get the source code of the eBay listing page.
  1. Dim r As HttpWebRequest = HttpWebRequest.Create(TextBox1.Text)
  2. Dim re As HttpWebResponse = r.GetResponse()
  3. Dim src As String = New StreamReader(re.GetResponseStream()).ReadToEnd()
Step 4: Finally, we want to extract the information from the page source code and output it in a messagebox.
  1. Try
  2.     Dim title As String = GetBetween(src, "id=""itemTitle"">", "</h1>")
  3.     Dim price As String = GetBetween(src, "itemprop=""price"">", "</span>")
  4.     MsgBox(title & vbNewLine & price)
  5. Catch ex As Exception
  6.     MsgBox("Information not found, has the bidding ended?")
  7. End Try
Project Complete! Below is the full source code and download to the project files.
  1. Imports System.Text.RegularExpressions
  2. Imports System.Net
  3. Imports System.IO
  4.  
  5. Public Class Form1
  6.     Private Function GetBetween(ByVal Source As String, ByVal Str1 As String, ByVal Str2 As String, Optional ByVal Index As Integer = 0) As String
  7.         Return Regex.Split(Regex.Split(Source, Str1)(Index + 1), Str2)(0)
  8.     End Function
  9.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  10.         Dim r As HttpWebRequest = HttpWebRequest.Create(TextBox1.Text)
  11.         Dim re As HttpWebResponse = r.GetResponse()
  12.         Dim src As String = New StreamReader(re.GetResponseStream()).ReadToEnd()
  13.         Try
  14.             Dim title As String = GetBetween(src, "id=""itemTitle"">", "</h1>")
  15.             Dim price As String = GetBetween(src, "itemprop=""price"">", "</span>")
  16.             MsgBox(title & vbNewLine & price)
  17.         Catch ex As Exception
  18.             MsgBox("Information not found, has the bidding ended?")
  19.         End Try
  20.     End Sub
  21. End Class

Add new comment