Solved

Automation of IE6

Posted on 2006-06-26
7
665 Views
Last Modified: 2012-05-05
Hi,

I would like some help with automating IE6.

In particular I wish to
1 - load a web page
2 - search the contents of the page to see if there are any pictures
3 - for pictures, determine the picture type, physical dimensions, size and any link that it may contain
4 - save the picture to the hard drive

Can someone please help

Thanks,
 Steve
0
Comment
Question by:sjeffress
  • 3
  • 2
7 Comments
 
LVL 1

Author Comment

by:sjeffress
ID: 16990248
Oh, sorry.  I forgot an important point.  I am using VBA (access).
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 16995054
The below is in VB but can be adapted to VBA. It doesn't include options for saving the images (or obtaining physical dimensions) as there are 2 methods you can use:

1.) Enumerate IE cache for the image, copy it from there, load the image into an StdPicture object and retrieve the dimensions.

2.) Download the file yourself (perhaps with URLDownloadToFile() API) and repeat the StdPicture method from #1 to retrieve dimensions.


Form1:
---------------------------
'Project -> References... -> Microsoft HTML Object Library
Option Explicit
Private Sub Command1_Click()
    Dim hDoc1 As HTMLDocument
    Dim hDoc2 As HTMLDocument
    '1 - load a web page
    Set hDoc1 = New HTMLDocument
    Set hDoc2 = hDoc1.createDocumentFromUrl("http://www.yahoo.com", vbNullString)
    Do Until (hDoc2.readyState = "complete")
        DoEvents
    Loop
    '2 - search the contents of the page to see if there are any pictures
    If Not (hDoc2 Is Nothing) Then
        Dim hImg As HTMLImg
        For Each hImg In hDoc2.images
            '3 - for pictures, determine the picture type, physical
            '    dimensions, size and any link that it may contain
            Debug.Print hImg.mimeType   'type
            Debug.Print hImg.src              'source
            Debug.Print hImg.fileSize        'size
            Debug.Print vbNullString
        Next
    End If
End Sub
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 16995070
0
 
LVL 1

Author Comment

by:sjeffress
ID: 16997071
Is there any way that internet explorer can display the page being accessed at the time?

Also, is there any way that i can get the link that sits behind the image.  eg. if you clicked on a picture and it went to www.google.com, how do i pick up that link?

Thanks.
0
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 250 total points
ID: 16997749
>>Is there any way that internet explorer can display the page being accessed at the time?
Several different approaches available.

1.) Use the WebBrowser component (essentially it's just IE). You can then, instead of using createDocumentFromUrl(), access the WebBrowser's Document instance (WebBrowser1.Document).

2.) Use CreateObject() to create a new instance of IE which you can automate.

    Dim ie As Object
    Set ie = CreateObject("InternetExplorer.Application")
    ie.Visible = True
    ie.navigate "www.yahoo.com"

You can thereafter access ie.Document after it has finished initializing.

3.) You can use ShellWindows to enumerate available IE instances and when you find the proper one, assume automation of it.

    'Project -> References -> Microsoft Internet Controls
    Dim ie As InternetExplorer
    Dim sw As New ShellWindows
    For Each ie In sw
        MsgBox ie.Document.body.outertext
    Next

>>is there any way that i can get the link that sits behind the image
Well, images and links are different elements within the DOM. An idea would be to...

Iterate through the Links collection and for each Link object, enumerate through its' children and see if any of them are Image elements. You can then compare that Image element against others or what-not.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

758 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now