Click to See Complete Forum and Search --> : How to get data from a web page?


newton11
03-17-2009, 03:49 PM
Hi,

I have this problem... Could you recommend me some object or library in .NET (C#) so I could obtain source code (HTML data) of given web page? I need to parse and analyze those data for my project...

Thanks a lot...

cridley
03-25-2009, 08:39 AM
HttpWebRequest Req = (HttpWebRequest)WebRequest.Create("http://www.google.com");
Req.Timeout = 60000;// 1 min
Req.AllowAutoRedirect = true;
HttpWebResponse Resp = (HttpWebResponse)Req.GetResponse();

//// Get the Response Stream
Stream respStream = Resp.GetResponseStream();
StreamReader sr = new StreamReader(respStream, Encoding.Default);
string respHTML = sr.ReadToEnd();
Resp.Close();

The string respHTML will now contain the source for www.google.com