到目前为止,在VBE中编写代码来创建解析器时,我已经使用了" img"标签和" src"属于刮图像,但我偶然发现我试图通过下面粘贴的部分。无法过滤我需要在我的代码中使用的部分来解析图像。
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
我正在使用的HTML示例:
<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>
答案 0 :(得分:1)
您可以访问&#34;样式&#34;属性我相信,所以
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