How to turn off Internet Explor image requests

I'm using the Internet Explorer control in a VB 6 project. I have the Visible property set to false but according to my Network Proxy Server it is requesting all the images, etc. Is there a way so it will only request the HTML? Other HTTP controls I've used in the past allowed you to turn off image requests to speed things up.
dnotestineAsked:
Who is Participating?
 
PaulHewsCommented:
>Very nice :-) At last, I meet someone who knows MS Regular Expressions.
Someone who has a basic grasp of them anyway... I'm still teaching myself to use them efficiently.

>How do I substitute the SubMatches(1) and SubMatches(2) if I need to.

There is the RegExp.Replace method, but in VB6, I usually find it lacks the granularity I need.  Here's a quick and dirty sample that walks through all the relative matches and replaces them depending on what they contain.  

Option Explicit

Private Sub Command1_Click()
    Dim strPage As String
    Dim strPath As String
    Dim strTemp As String
    Dim lngPos1 As Long, lngPos2 As Long
   
    strPage = OpenURL("http://www.experts-exchange.com/Software/Internet_Email/Web_Browsers/Internet_Explorer/Q_22718901.html")
    strPath = "Software/Internet_Email/Web_Browsers/Internet_Explorer/"
   
    Dim regex As RegExp
    Set regex = New RegExp
    regex.Pattern = "<a\s+href=""(http://)*(.*?)"".*?>\s*((\n|.)+?)\s*</a>"
    regex.Global = True
    regex.IgnoreCase = True
    Dim Matches As MatchCollection
    Set Matches = regex.Execute(strPage)
   
    lngPos1 = 1
    lngPos2 = 1
   
    Dim m As Match
    For Each m In Matches
        If Not m.SubMatches(0) = "http://" Then
           'Relative URL, convert to absolute:
           lngPos2 = m.FirstIndex + 1
           strTemp = strTemp & Mid$(strPage, lngPos1, lngPos2 - lngPos1)
           lngPos1 = lngPos2 + m.Length
           If Left$(m.SubMatches(1), 1) = "/" Then
                'relative to root
                strTemp = strTemp & "<a href=""http://www.mydomain.com" & m.SubMatches(1) & """>" & m.SubMatches(2) & "</a>"
           Else
                'relative to path
                strTemp = strTemp & "<a href=""http://www.mydomain.com/" & strPath & m.SubMatches(1) & """>" & m.SubMatches(2) & "</a>"
           End If
        Else
            Stop
        End If
        Debug.Print "Link: " & m.SubMatches(1)
        Debug.Print "Link text: " & m.SubMatches(2)
    Next
   
    Open "C:\temp\test.txt" For Output As #1
    Print #1, strTemp
    Close #1
    MsgBox "done"
   
   
End Sub



>f you would like I could ask another question so you could get more points as I think you've earned the ones for this question. Will you get notice of questions from me or how do I get notice to you?

So that it's fair for all the experts, just ask your questions.  I will get notice so I'll pop in and see if I can help.  :-)
0
 
PaulHewsCommented:
You can get the contents of HTML pages without loading the webbrowser control at all.  It's the easiest way to ensure you are only downloading what you requested.

Return the Contents of a Web Page Using WinInet API
http://www.freevbcode.com/ShowCode.Asp?ID=1252
0
 
dnotestineAuthor Commented:
Thats great code but my project revolves around manipulating link objects in the DOM object. How could I get the html string into a DOM object?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
PaulHewsCommented:
>Thats great code but my project revolves around manipulating link objects in the DOM object. How could I get the html string into a DOM object?

What kind of manipulation?  With a string you could parse out all the links and probably do whatever you needed to do with them as well.  (I'll help with the code if I know what you're trying to do.)  Since there's no user interaction, I'm not seeing what would require the heavy weight instance of a web browser control.
0
 
dnotestineAuthor Commented:
That would be great :-)
I need to be able to loop through every link, having the ability to modify the Anchor Text and/or the href url.

For 0 to AllLinks

   Get Anchor Text
   Get Href
   Look at both of them and put them back depending on the results
   Put some Anchor Text back
   Put a Href back

Next

0
 
PaulHewsCommented:
When you say "put them back" what do you mean?  Are you navigating to each of the links?  Are you showing the web browser at some point?
0
 
dnotestineAuthor Commented:
I'm looking at the links for matches, testing for relative links, adding a path if needed, etc. Then depending on this, I replace the old href.

For the Anchor text, I may change the wording and replace the old anchor text with it.
0
 
PaulHewsCommented:
Okay, but what's the end goal?  Showing the page in the webbrowser?  
0
 
dnotestineAuthor Commented:
The end goal is saving the DOM (converting to a string first)) to an HTML file, then after all the pages are done, FTP to a web site. Then the pages would be looked at by visitors to the web site.

A simple application of the program would be to move a web sites pages to another web site. The program would change the relative links to absolute, Head tag, etc, to make this possible

During the program execution, the pages are never seen in the browser.
0
 
PaulHewsCommented:
Here's a sample that shows how to parse out all the links from a page and determine if they are relative or absolute.  But let me know if I'm going in the right direction with this:

You need a reference to Microsoft VBScript Regular Expressions.  You also need the code from the link above in a module, with the OpenURL function set as Public.


Option Explicit

Private Sub Command1_Click()
    Dim strPage As String
   
    strPage = OpenURL("http://www.experts-exchange.com/Software/Internet_Email/Web_Browsers/Internet_Explorer/Q_22718901.html")
   
    Dim regex As RegExp
    Set regex = New RegExp
    regex.Pattern = "<a\s+href=""(http://)*?(.*?)"".*?>\s*((\n|.)+?)\s*</a>"
    regex.Global = True
    regex.IgnoreCase = True
    Dim Matches As MatchCollection
    Set Matches = regex.Execute(strPage)
    Dim m As Match
    For Each m In Matches
        If m.SubMatches(0) = "http://" Then
            Debug.Print "Absolute URL:"
        Else
            Debug.Print "Relative URL:"
        End If
        Debug.Print "Link: " & m.SubMatches(1)
        Debug.Print "Link text: " & m.SubMatches(2)
    Next
   
End Sub
0
 
dnotestineAuthor Commented:
Very nice :-) At last, I meet someone who knows MS Regular Expressions.

How do I substitute the SubMatches(1) and SubMatches(2) if I need to.

If you would like I could ask another question so you could get more points as I think you've earned the ones for this question. Will you get notice of questions from me or how do I get notice to you?
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.

All Courses

From novice to tech pro — start learning today.