Applecore Pages on Microsoft Access

Getting the names of image files from a web page

If you have a web page that is saved on your local hard drive, and you wish to get the names of all image files that are used in this page, then you can use some VBA code to open the html file as a text file, find any occurences of 'IMG', and extract the image name from that. Below is some sample code to do this, picking out only .gif file names:

Public Sub sGetIMGFileNames(strWebPage As String)
'   Code to extract any gif image names used in a web page.
'   Accepts:
'       strWebPage - the path and name of the web page that contains the image names
    On Error GoTo E_Handle
    Dim intFile As Integer
    Dim strInput As String, strDummy As String
    intFile = FreeFile
    Open strWebPage For Input As intFile
    Do
        Line Input #intFile, strInput
        Do While InStr(strInput, " 0 And InStr(strInput, ".gif") > 0
            strDummy = Mid(strInput, InStr(strInput, "<IMG") + 1)
            strInput = Mid(strInput, InStr(strInput, "<IMG") + 5)
            strDummy = Left(strDummy, InStr(strDummy, ">") - 1)
            strDummy = Mid(strDummy, InStr(strDummy, "SRC=") + 5)
            strDummy = Left(strDummy, InStr(strDummy, ".gif") + 3)
            Debug.Print strDummy
        Loop
    Loop Until EOF(intFile)
sExit:
    On Error Resume Next
    Close intFile
    Exit Sub
E_Handle:
    MsgBox Err.Description & vbCrLf & "sGetIMGFileNames", vbOKOnly + vbCritical, "Error: " & Err.Number
    Resume sExit
End Sub

Top

 


HOME | NEW | TABLES | QUERIES | FORMS | REPORTS | GENERAL | API | DOWNLOADS | TUTORIAL | RESOURCES
E-MAIL
Copyright & Disclaimer

 

Last modified at 06/06/2006 14:57:19