?
Solved

How to Load Web Page in web browser without image?

Posted on 2009-02-12
16
Medium Priority
?
1,809 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..
0
Comment
Question by:Yogesh_Agarwal
  • 8
  • 4
  • 4
16 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 23631102
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
 

Author Comment

by:Yogesh_Agarwal
ID: 23631399
can u give me code to do all thse please? i will accept as solution..
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 23631470
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:Yogesh_Agarwal
ID: 23631585
everything is in java and PHP..
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 23631599
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
 

Author Comment

by:Yogesh_Agarwal
ID: 23631604
how to remove those? i mean what command? i am just a beginner.. i would really appreciate the help.. :-)
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 23632386
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
 

Author Comment

by:Yogesh_Agarwal
ID: 23632525
give me some piece of code.. and i will full fill remain..
0
 
LVL 1

Accepted Solution

by:
sfinktah earned 2000 total points
ID: 23926787
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
 

Author Comment

by:Yogesh_Agarwal
ID: 23930029
THANKS FOR CODE.. DO U KNOW A WAY TO READ CAPTCHA IMAGE FROM IE CACHE?
0
 
LVL 1

Expert Comment

by:sfinktah
ID: 23937617
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
 

Author Comment

by:Yogesh_Agarwal
ID: 23940204
can we use web browser to do it?
0
 
LVL 1

Expert Comment

by:sfinktah
ID: 23964532
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
 

Author Comment

by:Yogesh_Agarwal
ID: 23967540
its coming as 404 error not found.. please help.
0
 
LVL 1

Expert Comment

by:sfinktah
ID: 23973337
404 not found.

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

Author Closing Comment

by:Yogesh_Agarwal
ID: 31546185
Excellent  Answer!!!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month16 days, 23 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question