1

I am making a simple web browser in Visual Studio c# which when opened goes to my website, I want to be able to somehow cut out bits of the html that gets rendered on the webpage. So far my WebBrowser works perfectly fine, i just need to be able to somehow listen to the incoming html code of the page, i will then remove the bits i don't need. Is it possible to do this with the WebBrowser in Visual Studio c#? If so could someone explain how it could be achieved.

Thanks

Hugh Macdonald
  • 143
  • 1
  • 12

1 Answers1

1

A first approach would be getting the HTML with a web request:

HttpWebRequest myReq =
(HttpWebRequest)WebRequest.Create("http://whatever.com/");
WebResponse response = myReq.GetResponse();
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd(); //Here's the complete HTML content
reader.Close ();
response.Close ();

After that you parse the HTML for your needs (delete something you don't need etc.)

For HTML parsing see this.

In the end you simply pass that parsed HTML to your WebBrowser, for example like this:

myWebBrowser.DocumentText =
    "<html><body>" + myParsedContent +
    "</body></html>";
Community
  • 1
  • 1
oopbase
  • 11,157
  • 12
  • 40
  • 59