Image url extraction using excel vba RRS feed

  • Question

  • I am using excel vba for image url extraction from webpage.I am unable to extract image url form below mentioned html code.

    <div class="img" style='background: url("https://images.jet.com/md5/bdebdedcf6bcbe76d12982db63d0c98b.500");'></div>

    I am using html.getElementsByClassName("img") but in output there is no image.I want to extract


    Tuesday, January 26, 2016 10:28 AM

All replies

  • Hi,

    I'd like to confirm:
      1. are you using Excel VBA, instead of VisualBasic?
      2. what you want to extract is "URL" (string like "https://~~"), instead of an image itself (or an image file)?

    Wednesday, January 27, 2016 7:12 AM
  • I am using excel vba.

    Yes,i want to extract url.


    Monday, February 1, 2016 4:27 AM
  • Hi,

    I've made a sample.

    Here's my code.
    Private Sub btnExtractURL_Click()
        Dim sourceString As String
        Dim rowIdx As Integer, rowMax As Integer
        Dim posFirst As Integer, posLast As Integer, chrLength As Integer
        rowMax = Range("A3").End(xlDown).Row
        ' ---
        For rowIdx = 3 To rowMax
            If Cells(rowIdx, 1).Value <> "" Then
                Cells(rowIdx, 2).Value = ""
                sourceString = Cells(rowIdx, 1).Value
                posFirst = InStr(sourceString, "http")
                posLast = InStr(posFirst, sourceString, """")
                chrLength = (posLast - 1) - (posFirst - 1)
                Cells(rowIdx, 2).Value = Mid(sourceString, posFirst, chrLength)
            End If
        ' ---
        MsgBox "finished"
    End Sub

    You can download "Extract_URL.xlsm". 

    • Edited by Ashidacchi Monday, February 1, 2016 4:48 AM
    Monday, February 1, 2016 4:45 AM