this is a webservice i used to scrape telephone directory information from
anywho.com. It's pretty rough code but you should get the general idea
[WebMethod]
public string PhoneLookup(string strNumber, ref int counter)
{
string strResult = string.Empty, searchtext = string.Empty;
try
{
// Create a new 'Uri' object with the specified string.
Uri myUri =new
Uri("
http://www.anywho.com/qry/wp_rl?npa="+strNumber.Substring(0,3) +
"&telephone="+ strNumber.Substring(3,7) + "&btnsubmit.x=36&btnsubmit.y=9");
// Creates an HttpWebRequest with the specified URL.
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(myUri);
myHttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
5.1; Q312461; .NET CLR 1.0.3705)";
HttpWebResponse res = (HttpWebResponse)myHttpWebRequest.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream(),
System.Text.Encoding.UTF8);
string pageContent = sr.ReadToEnd();
res.Close();
sr.Close();
int startpos = pageContent.IndexOf(@"bin/amap.cgi?") + 10;
if(startpos != -1)
{
int endpost = pageContent.IndexOf("Maps & Directions");
if(endpost != -1)
searchtext = pageContent.Substring(startpos, endpost - startpos + 17);
searchtext = searchtext.Replace(">Maps & Direct"," ");
searchtext = searchtext.Replace("gi?lastname="," ");
searchtext = searchtext.Replace("firstname=","\n");
searchtext = searchtext.Replace("+"," ");
searchtext = searchtext.Replace("="," ");
searchtext = searchtext.Replace("&"," ");
searchtext = searchtext.Replace("\\"," ");
searchtext = searchtext.Replace("\""," ");
searchtext = searchtext.Replace("city","\n");
searchtext = searchtext.Replace("state","\n");
searchtext = searchtext.Replace("zip","\n");
searchtext = searchtext.Replace("country","\n");
searchtext = searchtext.Replace("npatelephone","\n");
searchtext = searchtext.Replace("streetaddress","");
strResult = searchtext;
sr.Close();
pageContent = string.Empty;
}
}
catch
{
// return "No records exist";
// count++;
return null;
}
Agent.SelectedIndex = -1;
if(strResult.Trim() == string.Empty)
return null;
counter++;
return strResult + "\n\n";
}