Scrape href error

YasserKhalil

Well-known Member
Joined
Jun 24, 2010
Messages
852
Hello
I am trying to extract the urls from specific page ...
Code:
Sub Test()    Dim xmlPage             As New MSXML2.XMLHTTP60
    Dim htmlDoc             As New MSHTML.HTMLDocument
    Dim htmlResults         As MSHTML.IHTMLElementCollection
    Dim htmlResult          As MSHTML.IHTMLElement
    Dim strUrl              As String
    Dim ws                  As Worksheet
    Dim r                   As Long
    
    r = 2
    Set ws = Sheets("Sheet1")


    Application.ScreenUpdating = False
        xmlPage.Open "GET", "http://plants.newgarden.com/12190005/Catalog", False
        xmlPage.send
        
        If xmlPage.Status <> 200 Then
            MsgBox "Problem" & vbNewLine & xmlPage.Status & " - " & xmlPage.statusText
            Exit Sub
        End If
        
        htmlDoc.body.innerHTML = xmlPage.responseText
    
        Set htmlResults = htmlDoc.getElementsByClassName("CCPageText")
    
        For Each htmlResult In htmlResults
            
            If InStr(htmlResult.innerHTML, "href") > 0 Then
            Debug.Print htmlResult.innerHTML
            strUrl = htmlResult.getAttribute("href")
            End If
            Next htmlResult
    Application.ScreenUpdating = True
End Sub

I got error at this line
Code:
 strUrl = htmlResult.getAttribute("href")
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,214,894
Messages
6,122,124
Members
449,066
Latest member
Andyg666

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