Reverse Phone Lookup Address Verifier WebService
By Peter A. Bromberg, Ph.D.
Printer - Friendly Version
Peter Bromberg

Recently I had the opportunity to add reverse phone lookup to verify that phone numbers provided with leads were valid. I searched around and found Info USA's reverse lookup web interface, and quickly turned it into a screenscrape webservice.

I'm posting the code below without even a downloadable project because it's so simple. I could have used fancy Regex matches here, but sometimes it's fun just to use the "Brute Force" approach, playing around with substrings until you have scraped out what you want.

In this particular instance, we actually need to make two separate webrequests since the first page that comes back has one or more links containing the correct URL and querystring to return the phone number owner's name and address information in a subsequent page.



I present for your enjoyment the VB.NET version of my "Freebie Webscrape Info USA Reverse Phone Number Looker-Upper Webservice':

Imports System.Web.Services
Imports System.Net
Imports System.Text
Imports System.IO
Imports System.Diagnostics
<WebService(Namespace:="http://www.eggheadcafe.com/phoneLookup")> _
Public Class Service1
Inherits System.Web.Services.WebService
#Region " Web Services Designer Generated Code "
Public Sub New()
MyBase.New()
'This call is required by the Web Services Designer.
InitializeComponent()
'Add your own initialization code after the InitializeComponent() call
End Sub
'Required by the Web Services Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Web Services Designer
'It can be modified using the Web Services Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
components = New System.ComponentModel.Container
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
'CODEGEN: This procedure is required by the Web Services Designer
'Do not modify it using the code editor.
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

#End Region
<WebMethod()> Public Function LookUpPhone(ByVal strPhoneNumber As String) As String
Dim serverURL As String = "http://adp.infousa.com/fs?BAS_fssession=&BAS_vendor=0&bas_type=FADA&BAS_page=9&DAT_maxrecords=
                             10&BAS_flag=2&BAS_flag2=1&SCH_origdb=FADP&sch_fullphone=" & strPhoneNumber
Try

Dim req As HttpWebRequest = DirectCast(WebRequest.Create(serverURL), HttpWebRequest)
req.MaximumAutomaticRedirections = 60
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0b;Windows NT 5.0)"
Dim webresp As HttpWebResponse = DirectCast(req.GetResponse(), HttpWebResponse)
Dim strm As StreamReader = New StreamReader(webresp.GetResponseStream(), Encoding.ASCII)
Dim sContentTemp As String = strm.ReadToEnd()
strm.Close()
Dim URLList As New ArrayList
Dim startpos As Integer = sContentTemp.IndexOf("<A HREF=""/fs/consumer.htm") + 9
Dim endpost As Integer = sContentTemp.IndexOf("BAS_action=record")
URLList.Add("http://adp.infousa.com" & sContentTemp.Substring(startpos, endpost - startpos + 17))
Debug.WriteLine(URLList(0))
Dim req2 As HttpWebRequest = DirectCast(WebRequest.Create(URLList(0)), HttpWebRequest)
req2.MaximumAutomaticRedirections = 60
req2.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0b;Windows NT 5.0)"
Dim webresp2 As HttpWebResponse = DirectCast(req2.GetResponse(), HttpWebResponse)
Dim strm2 As StreamReader = New StreamReader(webresp2.GetResponseStream(), Encoding.ASCII)
Dim sContentTemp2 As String = strm2.ReadToEnd()
strm2.Close()
startpos = sContentTemp2.IndexOf("<!--END NAV BAR-->")
sContentTemp2 = sContentTemp2.Substring(startpos)
startpos = sContentTemp2.IndexOf("<font color=""#000000"" size=""2"">") + 34
endpost = sContentTemp2.IndexOf("call.click2talk.net2phone.com") - 24
Dim strResult As String = sContentTemp2.Substring(startpos, endpost - startpos)
strResult = strResult.Replace("<br>", "|")
strResult = strResult.Replace("&nbsp;", "|")
Dim lastpos As Integer = strResult.LastIndexOf("|")
strResult = strResult.Substring(0, lastpos)
Return strResult
Catch
Return Nothing
End Try
End Function
End Class

The code is yours to play with, I hope you enjoy it. The folks at Info USA primarily use this as a feeder to their excellent business leads and other offerings, so please do patronize their fine site.

 


Peter Bromberg is a C# MVP, MCP, and .NET consultant who has worked in the banking and financial industry for 20 years. He has architected and developed web - based corporate distributed application solutions since 1995, and focuses exclusively on the .NET Platform. Pete's samples at GotDotNet.com have been downloaded over 41,000 times. You can read Peter's UnBlog Here.  --><--NOTE: Post QUESTIONS on FORUMS!
Do you have a question or comment about this article? Have a programming problem you need to solve? Post it at eggheadcafe.com forums and receive immediate email notification of responses.