Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Automation of IE6

Posted on 2006-06-26
7
Medium Priority
?
673 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 1000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

972 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