Excel Can';t从网页中刮取页面源中可用的图像链接

Excel Can';t从网页中刮取页面源中可用的图像链接,excel,vba,web-scraping,xmlhttprequest,Excel,Vba,Web Scraping,Xmlhttprequest,我正在尝试使用xmlhttp请求从数据库获取配方图像链接。图像链接在页面源中的某个样式属性中可用。 然而,当我像下面这样尝试时,我得到背景图像作为输出,而style的值包含图像链接 到目前为止,我已经尝试过: Sub GrabImageLink() Const Url$ = "https://www.yumm.ca/en/recipe/salmon-green-curry-1" Dim HTML As HTMLDocument, Http As Object

我正在尝试使用xmlhttp请求从数据库获取配方图像链接。图像链接在页面源中的某个样式属性中可用。 然而,当我像下面这样尝试时,我得到
背景图像
作为输出,而style的值包含图像链接

到目前为止,我已经尝试过:

Sub GrabImageLink()
    Const Url$ = "https://www.yumm.ca/en/recipe/salmon-green-curry-1"
    Dim HTML As HTMLDocument, Http As Object
    
    Set HTML = New HTMLDocument
    Set Http = CreateObject("MSXML2.XMLHTTP")

    With Http
        .Open "Get", Url, False
        .setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36"
        .send
        HTML.body.innerHTML = .responseText
    End With
    
    Debug.Print HTML.querySelector(".recipe-visual").getAttribute("style")
End Sub
电流输出:

background-image
预期产出:

https://cdn.yumm.ca/uploads/images/572b58ad0ed35a3d0294484ec535a131/salmon-green-curry@2x_s.jpg

在JS中,这同样令人讨厌。要获取属性值,您必须直接引用style属性,因此使用以下命令即可:

HTML.querySelector(".recipe-visual").Style.backgroundImage
一旦您键入了方便的
HTML.querySelector(“.recipe visual”).Style,代码编辑器实际上会为您提供所有可用属性的弹出窗口