Extract Picture Links as Text in VBA

k0023382

New Member
Joined
Feb 25, 2010
Messages
45
I have been trying to get my ahead around this, however I do not how to use getElementsByClassName to get this done.

For instance, from the link:
www.cvvillas.com/Destinations/Greece/Kefalonia/Villa-Isicos/Villa-Isicos-Gallery

I need to extract the links of the pictures, 14 of them and copy them on cells on Excel
cell A1=> "/CVTravel/media/CVTravel/Destinations/Greece/Kefalonia/Villa%20Isicos/14-min.jpg?width=999&height=667&ext=.jpg"
cell A2=> "/CVTravel/media/CVTravel/Destinations/Greece/Kefalonia/Villa%20Isicos/13-min.jpg?width=999&height=667&ext=.jpg"
etc

I do not need the pictures, just the text under that produces the link.

Maybe there is another way of doing without using getElementsByClassName that it is easier.

Thanks in advance
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Try this;

Code:
Sub GetLinks()
    Dim HTTP As Object, HTML As Object, URL As String, i As Integer
    
    URL = "http://www.cvvillas.com/Destinations/Greece/Kefalonia/Villa-Isicos/Villa-Isicos-Gallery"

    Set HTML = CreateObject("HTMLFILE")
    Set HTTP = CreateObject("MSXML2.XMLHTTP")
    
    HTTP.Open "GET", URL, False
    HTTP.send
    
    HTML.body.innerHTML = HTTP.ResponseText
    
    Set Images = HTML.getElementsByTagName("img")
    i = 0
    
    Do While i < Images.Length
        Range("A" & i + 1) = Images(i).src
        i = i + 1
    Loop
    
    Set HTML = Nothing
    Set HTTP = Nothing

End Sub
 
Last edited:
Upvote 0
For live image links, you better try this;

Code:
Sub GetLinks2()
    Dim IE As Object, URL As String, i As Integer
    
    URL = "http://www.cvvillas.com/Destinations/Greece/Kefalonia/Villa-Isicos/Villa-Isicos-Gallery"

    Set IE = CreateObject("InternetExplorer.Application")
    IE.Navigate URL
    
    Do While IE.busy
        DoEvents
    Loop
    Do Until IE.ReadyState = 4
        DoEvents
    Loop
    
    Set Images = IE.Document.getElementsByTagName("img")
    i = 0
    
    Do While i < Images.Length
        Range("A" & i + 1) = Images(i).src
        i = i + 1
    Loop
    
    Set HTML = Nothing
    Set HTTP = Nothing

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top