Introduction
I must start by stressing that this is for educational purposes only!! Ok, now that I got that out of the way.
The purpose of this project is to demostrate how to extract data from a website.
Lets get right to the good stuff.....the code!
The Code
The first step is to format the url with all the required information.
<P><FONT color=#0000ff size=2>Function</FONT><FONT size=2> ReplaceSpaceWithPlusSign(</FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> vStr </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String</FONT><FONT size=2>) </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2> Dim</FONT><FONT size=2> strTemp </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2> Try</P></FONT><FONT size=2><P> strTemp = Replace(vStr, vbTab, " ")</P><P> strTemp = Replace(strTemp, vbCr, " ")</P><P> strTemp = Replace(strTemp, vbLf, " ")</P><P> strTemp = Replace(strTemp, " ", "+")</P><P></FONT><FONT color=#008000 size=2>
<FONT size=2><P>strAdd = ReplaceSpaceWithPlusSign(txtAddress.Text)</P><P>strCity = ReplaceSpaceWithPlusSign(Trim(txtCity.Text))</P><P>strState = ReplaceSpaceWithPlusSign(cmbState.Text)</P><P></FONT><FONT color=#008000 size=2>
Now that you have the correcly formatted URL pass it to a function to read the websites source code.
<FONT size=2><P></FONT><FONT color=#0000ff size=2>Public</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Function</FONT><FONT size=2> ReadWebSite(</FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> URL </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String</FONT><FONT size=2>) </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2> Dim</FONT><FONT size=2> req </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> HttpWebRequest</P><P></FONT><FONT color=#0000ff size=2> Dim</FONT><FONT size=2> res </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> HttpWebResponse</P><P></FONT><FONT color=#0000ff size=2> Dim</FONT><FONT size=2> strContents </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2> Dim</FONT><FONT size=2> StrStream </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> Stream</P><P></FONT><FONT color=#0000ff size=2> Dim</FONT><FONT size=2> Cok </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> Cookie</P><P></FONT><FONT color=#0000ff size=2> Dim</FONT><FONT size=2> oWebResponse </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> WebResponse</P><P></FONT><FONT color=#0000ff size=2> Dim</FONT><FONT size=2> oReturnStream </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> Stream</P><P></FONT><FONT color=#0000ff size=2> Dim</FONT><FONT size=2> oReturnStreamReader </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> StreamReader</P><P></FONT><FONT color=#0000ff size=2> Dim</FONT><FONT size=2> myReq </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> HttpWebRequest</P><P></FONT><FONT color=#0000ff size=2> Dim</FONT><FONT size=2> myResponse </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> HttpWebResponse</P><P> </P><P> req = </FONT><FONT color=#0000ff size=2>Nothing</P></FONT><FONT size=2><P> res = </FONT><FONT color=#0000ff size=2>Nothing</P></FONT><FONT size=2><P> strContents = </FONT><FONT color=#0000ff size=2>Nothing</P></FONT><FONT size=2><P> StrStream = </FONT><FONT color=#0000ff size=2>Nothing</P></FONT><FONT size=2><P> Cok = </FONT><FONT color=#0000ff size=2>Nothing</P></FONT><FONT size=2><P> oWebResponse = </FONT><FONT color=#0000ff size=2>Nothing</P></FONT><FONT size=2><P> oReturnStream = </FONT><FONT color=#0000ff size=2>Nothing</P></FONT><FONT size=2><P> oReturnStreamReader = </FONT><FONT color=#0000ff size=2>Nothing</P></FONT><FONT size=2><P> myReq = </FONT><FONT color=#0000ff size=2>Nothing</P></FONT><FONT size=2><P> myResponse = </FONT><FONT color=#0000ff size=2>Nothing</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2>Try</P></FONT><FONT size=2><P></FONT><FONT color=#008000 size=2>
Now that you have the source code pass it to another function that uses regular expressions to find the zip code.
<FONT size=2><P></FONT><FONT color=#0000ff size=2>Public</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>Function</FONT><FONT size=2> GetZipCodeFromWeb(</FONT><FONT color=#0000ff size=2>ByVal</FONT><FONT size=2> str </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String</FONT><FONT size=2>) </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2> Dim</FONT><FONT size=2> RemoveNonDigits </FONT><FONT color=#0000ff size=2>As</FONT><FONT size=2> </FONT><FONT color=#0000ff size=2>String</P></FONT><FONT size=2><P></FONT><FONT color=#008000 size=2>
Thats it!!