user7664559
user7664559

Reputation:

How to sift through the tag name for image from the pasted elements

So far, while writing code in VBE to make a parser I have used the "img" tag and the "src" attribute to scrape an image but I stumbled trying to go through the portion I'm pasting below. Can't filter the portion I need to use in my code to parse an Image.

Set topics = html.getElementsByClassName("card card-lg")
For i = 0 To topics.Length - 1
Set topic = topics(i)
    Cells(x, 1).Value = topic.getElementsByClassName("wine-card__image-wrapper")(0).getElementsByTagName("img")(0).src
    x = x + 1
Next i

And a sample of the HTML I'm working with:

<div class="wine-card__image-wrapper">
<a href="/wineries/tschida/wines/angerhof-eiswein-gruner-veltliner-2012">
<figure class="wine-card__image" style="background-image: url(//images.vivino.com/thumbs/qlER3oggQVKh1FZn7YGxZg_375x500.jpg)">
<div class="image-inner"></div>
</figure>
</a>
</div>

Upvotes: 0

Views: 176

Answers (1)

Nathan_Sav
Nathan_Sav

Reputation: 8531

You can access the "style" attribute I believe, so

Sub t()

Dim ie As SHDocVw.InternetExplorer
Dim d As MSHTML.HTMLDocument
Dim dv As MSHTML.HTMLDivElement
Dim ha As MSHTML.IHTMLElement

Set ie = New SHDocVw.InternetExplorer
ie.Visible = True

ie.navigate "https://www.vivino.com/explore?e=eJzLLbI11jNVy83MswWSiRW2RgZqyZW26Ulq5SXRsbaGAKA_Cdk%3D"

While ie.Busy Or ie.readyState <> READYSTATE_COMPLETE: DoEvents: Wend

Set d = ie.document
Set e = d.getElementsByClassName("wine-card__image-wrapper")(0)
Set ha = e.Children(0).Children(0)
Debug.Print ha.Style.backgroundImage

End Sub

Upvotes: 1

Related Questions