i've tried various element search methods like class, name, and id, but it's not working

91 Views Asked by At

I've been attempting Excel Web Scraping with WinHTTP, and I've tried various element search methods like class, name, and id, but it's not working. Scraping works on other sites, but it's not working well on this website. What I want to scrape is the product name and the URL of the picture. Can anyone help? the code is below

Sub WebScrapingWithWinHTTP()
    Dim objWinHTTP As Object
    Set objWinHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")

    Dim url As String
    url = "https://www.outre.com/new/"

    objWinHTTP.Open "GET", url, False
    objWinHTTP.send

    Dim html As String
    html = objWinHTTP.responseText

   
    Dim htmlDoc As Object
    Set htmlDoc = CreateObject("htmlfile")
    htmlDoc.body.innerHTML = html

    
    Dim elements As Object
    Set elements = htmlDoc.getElementsByClassName("uppercase.font-bold.text-[16px].xs:text-[1.3vw].lg:text-[14px]")

    If elements.Length > 0 Then
        Dim element As Object
        Set element = elements.Item(1)
        Dim title As String
        title = element.innertext
    
        Sheets("Sheet1").Range("A1").Value = title
    Else
        Sheets("Sheet1").Range("A1").Value = "nothing"
    End If

    Set objWinHTTP = Nothing
    Set htmlDoc = Nothing
End Sub

0

There are 0 best solutions below