ANmaHTMLImgDownload

Downloads image from src of < img html tag after searching for list of conditions in FullListCond.
Similar to Between_HTMLtag but will actually download the image that is found in < img (src parameters).
Might need some work on possible relative paths in src, but should work in general.
FullListCond can be like ...
Consolidated Statement of Income{|}Net sales{|}{~}

CodeFunctionName
What is this?

Public

Not Tested

Original Work
Function ANmaHTMLImgDownload(Optional FromURL = "", Optional Or_FullPage = "", Optional FullListCond = "SearchFor{|}Then For{|}Then find between me{~} and me", Optional SaveTo = "C:\Images\")
    ' Downloads an image from a webpage matching condition string list criteria, please read ...
    '    Downloads it into SaveTo with same extension
    '    Returns 0 if fail for any reason, 1 if downloaded
    ' Needs VBInstr(), DownloadFile(), GetSon(), CutString()
    ' Needs Navigate() only if or_FullPage is not passed
    ' FromURL:             URL for the page
    ' SaveTo:             The full path and file name without extension to ave image to.
    ' or_FullPage:     or if FromURL is not passed, need to pass the full page html
    ' FullListCond:     List of strings separated by {|} to search for inside the page, then final item should have character {~} to identify what to read from ...
    '            Example: Consolidated Statement of Income </span >{|}Net sales </span >{|} <td {|} <span {|} <ix:{|} >{~} </ix:
    '            Tool will search for ... Consolidated Statement of Income </span >
    '                in page
    '            Then for ... Net sales </span >
    '            Then for ... <td
    '            Then for ... <span
    '            Then for ... <ix:
    '            Then preserves what between > and </ix:
    '                text " src=" is expected to be found in string resutled out form above
    '
    Rett = 0
    Page6 = Or_FullPage
    If FromURL > "" And Or_FullPage = "" Then Page6 = Navigate(Cstr(FromURL), "")
    If Page6 = "" Then goto ByeBye
    Crowler = 0
    ImgTag = ""
    For Each Con1 In Split(FullCond, "{|}")
        If Con1 = "" Then GoTo NextCon1
        If VBInstr("{~}", Con1) > 0 Then
            Crowler = VBInstr(CutString3(Con1, 1, "{~}"), Page6, Crowler + 1)
            CrLen = VBInstr(CutString3(Con1, 2, "{~}"), Page6, Crowler + 1) - Crowler
            ImgTag = Mid(Page6, Crowler + 1, CrLen - 1)
            Exit For
        Else
            Crowler = VBInstr(Con1, Page6, Crowler + 1)
        End If
NextCon1:
    Next
    ImgID = VBInstr(" <img ", ImgTag)
    SrcID = VBInstr(" src=", ImgTag)
    If ImgID > 0 And SrcID > 0 And ImgID < SrcID Then ' If we found Img inside mid area
        ' Now downloading ....
        ImgRemote = CutString(ImgTag, " src=", """)
        ImgRemoteFile = GetSon(ImgRemote)
        DownloadFile ImgRemote, Saveto & ImgRemoteFile
        Rett = 1
    End If
ByeBye:
    ANmaHTMLImgDownload = Rett
End Function

Optional FromURL = "", Optional Or_FullPage = "", Optional FullListCond = "SearchFor{|}Then For{|}Then find between me{~} and me", Optional SaveTo = "C:\Images\"

Views 106

Downloads 38

CodeID
DB ID