Getting the source of WebPage in C#

Here is a code that comes in handy whenever we need take something out of source HTML

The below code in Selenium will give the full source of the HTML or anyother file. (this is a normal C# lines not related with Selenium)

 

 public static string GetFullWebPage(String url)
  {

            WebRequest request = WebRequest.Create(url);
            WebResponse response = request.GetResponse();
            Stream dataStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream);
            string responseFromServer = reader.ReadToEnd();
            return responseFromServer;

   }

 

 

You may also like...