0

I have big problem in scraping webpage

I needed scraping img src adrress but result is "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGP6zwAAAgcBApocMXEAAAAASUVORK5CYII="

At first I didn't this but after I Knew that but I can't decode

I try to search about base64 png image but I can't try to code at all. I need your help

  • 1
    Here you find samples: https://stackoverflow.com/questions/169907/how-do-i-base64-encode-a-string-efficiently-using-excel-vba – AHeyne Apr 11 '20 at 07:38
  • 1
    If you're looking for a source URL then there isn't one: the image is encoded directly on the page. – Tim Williams Apr 11 '20 at 08:28

1 Answers1

0

Give this a try. I wrote two functions DecodeBase64 and WriteByteArrayToFile. DecodeBase64 takes in a Base64 encoded string and returns the Byte() from this. WriteByteArrayToFile takes in a Byte() and a FilePath as string, and will write this Byte() to a file.

Update this section "YOURPATHGOESHERE\Picture.png" in the Example Sub to a valid file path on your computer, see if this code does what you are after. I'm getting a very small picture of what appears to be a square when running the code below.

Code

Option Explicit

'Decode Base64 string into a byte array
Public Function DecodeBase64(ByVal Base64String As String) As Byte()
    With CreateObject("MSXML2.DOMDocument").createElement("b64")
        .DataType = "bin.base64"
        .Text = Base64String
        DecodeBase64 = .nodeTypedValue
    End With
End Function

'Take a byte array and write to a file
Public Sub WriteByteArrayToFile(FileData() As Byte, ByVal FilePath As String)
    Dim FileNumber As Long: FileNumber = FreeFile
    Open FilePath For Binary Access Write As #FileNumber
    Put #FileNumber, 1, FileData
    Close #FileNumber
End Sub

'Run from here
Sub example()
    WriteByteArrayToFile DecodeBase64("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGP6zwAAAgcBApocMXEAAAAASUVORK5CYII="), "YOURPATHGOESHERE\Picture.png"
End Sub
Ryan Wildry
  • 5,612
  • 1
  • 15
  • 35