VBA Error - Site change get images links

tactos

New Member
Joined
Jan 6, 2019
Messages
7
I already had one person's help to get the code and I got it working without problems.
Now I think the site has changed and now I can not get results.
Code:
[COLOR=#454545][FONT=&quot][B]Public Function getHeroImage(productUrl As String) As String[/B][/FONT][/COLOR]
[COLOR=#454545][FONT=&quot]
[/FONT][/COLOR]
[COLOR=#454545][FONT=&quot][B]    Dim dom As HTMLDocument[/B][/FONT][/COLOR]
[COLOR=#454545][FONT=&quot][B]    Set dom = New HTMLDocument[/B][/FONT][/COLOR]
[COLOR=#454545][FONT=&quot][B]    With CreateObject("winhttp.winhttprequest.5.1")[/B][/FONT][/COLOR]
[COLOR=#454545][FONT=&quot][B]        .Open "GET", productUrl, False[/B][/FONT][/COLOR]
[COLOR=#454545][FONT=&quot][B]        .send[/B][/FONT][/COLOR]
[COLOR=#454545][FONT=&quot][B]        dom.body.innerHTML = .responseText[/B][/FONT][/COLOR]
[COLOR=#454545][FONT=&quot][B]        getHeroImage = dom.querySelector("div.goodsIntro_largeImgWrap > img").getAttribute("data-zoom")[/B][/FONT][/COLOR]
[COLOR=#454545][FONT=&quot][B]    End With[/B][/FONT][/COLOR]
[COLOR=#454545][FONT=&quot]
[/FONT][/COLOR]
[COLOR=#454545][FONT=&quot][B]End Function[/B][/FONT][/COLOR]
I basically wanted to have the links of the images in a column. The code I was using was as follows:
but now it does not return results.
I've tried changing the selector to:
Code:
[COLOR=#454545][FONT=&quot][B]dom.querySelector ("div.goodsIntro_largeImgWrap> # js-goodsNormalImg> img"). getAttribute ("data-zoom")[/B][/FONT][/COLOR]
but it did not work.
Can someone help please? What have I done wrong to change in the next?
Website I want to get the pictures: https://www.gearbest.com/cell-phones...601631974.html
 
Upvote 0

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.
New version:

Code:
Public Function GetInfo3(w$)
Dim res$, html As HTMLDocument, Elements As Object, i%
With CreateObject("MSXML2.XMLHTTP")
    .Open "GET", w, False
    .setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
    .Send
    res = StrConv(.responseBody, 64)
End With
Set html = New HTMLDocument
With html
    .Body.innerHTML = res
    Set Elements = .getElementsByTagName("img")
    For i = 0 To Elements.Length - 1
        If Not IsNull(Elements(i).getAttribute("data-img")) Then
            GetInfo3 = Elements(i).getAttribute("data-img")
            Exit Function
        End If
    Next
End With
End Function
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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