We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

How to Load Web Page in web browser without image?

Medium Priority
1,870 Views
Last Modified: 2013-11-05
hi,

I have a web browser control and i want to Load a web page without loading its pictures and scripts. I dont want to use httpclient, webrequest etc. i just want VB.net Code to do so. Please Help me..
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
You said you dont want to use the httpclient, or webrequest etc but these are the VB.NET objects. I dont think there is any property within the webbrowser control for this behaviour. I think you need to download the page using webrequest and do not load the pictures and script files. Then you can parse the code of the page removing all the embeded scripts and all the links to pictures.

Author

Commented:
can u give me code to do all thse please? i will accept as solution..
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:

Author

Commented:
everything is in java and PHP..
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
The ideas behind the code are universal. You have to go through the html, find out if there are any <script> tags and if you do find them remove everything between <script> and </script> including the tags themselves. Also search for the img tags and remove them or replace the links to some global picture which idealy would say that picture has been blocked etc.

Author

Commented:
how to remove those? i mean what command? i am just a beginner.. i would really appreciate the help.. :-)
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
I dont think you would be able to get a working solution fulfulling 100% of your requirements. At least i wont be able to produce a full blown working solution for you.

Author

Commented:
give me some piece of code.. and i will full fill remain..
Commented:
I was just about to post your exact question, but you've saved me the trouble.

Here is an answer in C# (sorry), It's in it's own namespace, so you should be able to include in your project somehow... I can compile it into an assembly if you need.

It's a static method, so you just need to do something like this (again, C#, but will look fairly similar in VB):

With your Browser, do something like this:

webBrowser1.DocumentText = CSharp.cc.Net.Web.ErsatzWebBrowser("http://google.com");

and that should be about it.

Code is untested, it came from a much larger (working) library, but there were no compilation errors.


using System;
using System.IO;
using System.Net;
using System.Text;
using System.Web;
 
namespace CSharp.cc.Net.Web
{
    public class ErsatzWebBrowser
    {
        static public String Navigate(String siteURL)
        {
 
            HttpWebRequest httpRequest = null;
            httpRequest = (HttpWebRequest)WebRequest.Create(siteURL);
            httpRequest.AllowAutoRedirect = true;
            HttpWebResponse WebResponse = null;
            Stream responseStream = null;
            String Html = String.Empty;
            
            try
            {
                WebResponse = (HttpWebResponse)httpRequest.GetResponse();
                responseStream = WebResponse.GetResponseStream();
                StreamReader Reader = new StreamReader(responseStream, Encoding.Default);
                Html = Reader.ReadToEnd();
            }
            
            catch (WebException we)
            {
                Console.Error.WriteLine("Error: " + we.Message);
            }
            finally
            {
                if (WebResponse != null)
                {
                    WebResponse.Close();
                    responseStream.Close();
                }
            }
 
            return Html;
        }
    }
}

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
THANKS FOR CODE.. DO U KNOW A WAY TO READ CAPTCHA IMAGE FROM IE CACHE?

Commented:
To get very untechnical, they're set "not to cache", so it won't be in there.

If you are grabbing the HTML only, then you can parse to find the image src, and download it fairly easily.

That should work - as it hasn't been generated until it's loaded, you have one shot.

Author

Commented:
can we use web browser to do it?

Commented:
You can use anything, as long as you only load it once.

You might find a PictureBox easier though, you can include it on a WinForm using the Visual Basic IDE and set the URL:

            this.pictureBox1.ImageLocation = "http://www.captcha.org/images/unique1238974"

(C# again, but you get the idea)

Author

Commented:
its coming as 404 error not found.. please help.

Commented:
404 not found.

I'd have to see the URL that uses the captcha.

Author

Commented:
Excellent  Answer!!!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.