• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1820
  • Last Modified:

How to Load Web Page in web browser without image?

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..
0
Yogesh_Agarwal
Asked:
Yogesh_Agarwal
  • 8
  • 4
  • 4
1 Solution
 
CodeCruiserCommented:
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.
0
 
Yogesh_AgarwalAuthor Commented:
can u give me code to do all thse please? i will accept as solution..
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
Yogesh_AgarwalAuthor Commented:
everything is in java and PHP..
0
 
CodeCruiserCommented:
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.
0
 
Yogesh_AgarwalAuthor Commented:
how to remove those? i mean what command? i am just a beginner.. i would really appreciate the help.. :-)
0
 
CodeCruiserCommented:
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.
0
 
Yogesh_AgarwalAuthor Commented:
give me some piece of code.. and i will full fill remain..
0
 
sfinktahCommented:
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

0
 
Yogesh_AgarwalAuthor Commented:
THANKS FOR CODE.. DO U KNOW A WAY TO READ CAPTCHA IMAGE FROM IE CACHE?
0
 
sfinktahCommented:
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.
0
 
Yogesh_AgarwalAuthor Commented:
can we use web browser to do it?
0
 
sfinktahCommented:
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)

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

I'd have to see the URL that uses the captcha.
0
 
Yogesh_AgarwalAuthor Commented:
Excellent  Answer!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 8
  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now