lundi 30 novembre 2020

Getting first image URL from a website using excel vba

I have been trying to get one image URL only from a website, So far I'm successful of getting ALL the image but I only need the second result because the first is like this (data:image/svg+xml;base64,PHN2ZyB4b.....) which I don't need. I only need this result (https://website/v1606373379/N37935382A_1.jpg) but I only want one as well and there total of more or less 10 images in the website.

Sample HTML of the image that I want.

<img id="currentImage" style="width: 100%; border: 1px solid #eee;" src=" https://website/v1606067766/N41880794A_1.jpg ">

This is what I have come up so far:

Sub Image()

Dim ie As InternetExplorer
Dim ht As HTMLDocument
Dim SourceCell As Range
Dim ElementCol As Object, Link As Object
Dim ecol As Long

Set ie = New InternetExplorer


For Each SourceCell In Sheets("Sheet1").Range("C2:C4")

If IsEmpty(SourceCell) = True Then

MsgBox "END!"

Exit Sub
   
End If

If IsEmpty(SourceCell) = False Then

    With ie
      .navigate SourceCell
      .Visible = True
    End With
    Do While ie.Busy
      DoEvents
    Loop
    
End If

Set ht = ie.document

Application.Wait (Now + TimeValue("00:00:02"))



    Set ElementCol = ht.getElementsByTagName("img")


    For Each Link In ElementCol
    ecol = Sheet2.Cells(Rows.Count, 1).End(xlUp).row + 1
    Cells(ecol, 1).Value = Link.src

Next

Next

End Sub



Aucun commentaire:

Enregistrer un commentaire