Call following function for scraping:
protected void GetValueofFirstPage()
{
DataTable dt = new DataTable();
dt = CreateTable();
string strURL = "http://wsa2009.expoplanner.com/plsearch.wcs?searchby=all&seekword=null&alpha=all&filter=";
String strResult;
WebResponse objResponse;
WebRequest objRequest = HttpWebRequest.Create(strURL);
objResponse = objRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
//strResult = sr.ReadToEnd();
while ((strResult = sr.ReadLine()) != null)
{
if (strResult.Contains("Booth"))
{
flage = 1; ;
}
if (flage == 1)
{
if (strResult.Contains("href") && strResult.Contains("?"))
{
DataRow dr = dt.NewRow();
string[] str = strResult.Split('>');
string[] path = str[0].Split('\"');
str[1] = str[1].Replace("ANCHOR TAG END ~<~/~A~", "");
dr[0] = str[1];
dr[1] = "http://wsa2009.expoplanner.com/" + path[1];
dt.Rows.Add(dr);
Response.Write(str[1] + ' ' + path[1]);
Response.Write("LINE BREAK <~B~R~/~>");
//Session["dt"] = dt.ToString();
Session["dt"] = dt;
}
}
}
sr.Close();
flage = 0;
}
grd.DataSource = dt;
grd.DataBind();
}
No comments:
Post a Comment